Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Friday, February 13, 2015

Introduction material-design

Introduction material-design


Please More Details....
http://www.google.com/design/spec/material-design/introduction.html



Sunday, June 2, 2013

Turn Wifi On/Off using WifiManager.setWifiEnabled() or WifiManager.setWifiDisabled()

Turn Wifi On/Off using WifiManager.setWifiEnabled() or WifiManager.setWifiDisabled()

Step 1:  ADD Or modify main.xml to add to button. in Layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<TextView 
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="@string/hello"
   />
<TextView 
   android:id="@+id/wifistate"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   />
<Button
   android:id="@+id/onwifi"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Turn Wifi On"
   />
<Button
   android:id="@+id/offwifi"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="Turn Wifi Off"
   />
</LinearLayout> 

Step 2: Add Or change code in your MainActivity Class.

package com.exercise.WifiStateChangedValkesh; 
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class WifiStateChangedValkesh extends Activity {
 
 TextView WifiState;
 
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       WifiState = (TextView)findViewById(R.id.wifistate);
       Button OnWifi = (Button)findViewById(R.id.onwifi);
       Button OffWifi = (Button)findViewById(R.id.offwifi);
      
       this.registerReceiver(this.WifiStateChangedReceiver,
               new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
      
       OnWifi.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(true);
   }});
      
       OffWifi.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    WifiManager wifiManager = (WifiManager)getBaseContext().getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(false);
   }});
   }
  
   private BroadcastReceiver WifiStateChangedReceiver
   = new BroadcastReceiver(){

  @Override
  public void onReceive(Context context, Intent intent) {
   // TODO Auto-generated method stub
   
   int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE ,
     WifiManager.WIFI_STATE_UNKNOWN);
   
   switch(extraWifiState){
   case WifiManager.WIFI_STATE_DISABLED:
    WifiState.setText("WIFI STATE DISABLED");
    break;
   case WifiManager.WIFI_STATE_DISABLING:
    WifiState.setText("WIFI STATE DISABLING");
    break;
   case WifiManager.WIFI_STATE_ENABLED:
    WifiState.setText("WIFI STATE ENABLED");
    break;
   case WifiManager.WIFI_STATE_ENABLING:
    WifiState.setText("WIFI STATE ENABLING");
    break;
   case WifiManager.WIFI_STATE_UNKNOWN:
    WifiState.setText("WIFI STATE UNKNOWN");
    break;
   }
   
  }};
}
 

Step 3: Add permission "android.permission.CHANGE_WIFI_STATE" AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.exercise.WifiStateChangedValkesh"
     android:versionCode="1"
     android:versionName="1.0">
   <application android:icon="@drawable/icon" android:label="@string/app_name">
       <activity android:name=".WifiStateChangedValkesh"
                 android:label="@string/app_name">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>

   </application>
   <uses-sdk android:minSdkVersion="4" />
   <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
</manifest>

Saturday, June 1, 2013

How to enable fast scrolling in Android

Fast Scrolling in Android happens when you have a lot of items in your screen and you need to scroll fast. When it is activated you well see an small box coming from the right of the screen and when you drag it up or down it goes really fast. You can see this in your contact list, email or any application that has a lot of data and is sorted alphabetically.

There are 2 ways to enable this functionality in your application:
By adding the property in your XML layout file:



    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fastScrollEnabled="true" />

or by adding it in your java code:

      getListView().setFastScrollEnabled(true);

Wednesday, May 8, 2013

programmatically-set-weight-for-button in android

You are create when Dynamically button then set weight without use xml.
then use it this code
  
LinearLayout.LayoutParams size = new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
size.weight = 1; 
 
Button btn = new Button(MainActivity.this);  
btn.setLayoutParams(size);
 
 
You have to use TableLayout.LayoutParams
TextView tv = new TextView(v.getContext());
tv.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
LayoutParams.WRAP_CONTENT, 1f));  

Tuesday, May 7, 2013

WIFI Connection in Android

Check WIFI is ON Or OFF In your android application 
First  to  add This line in Your AndroidManifest.xml
android.permission.ACCESS_NETWORK_STATE  
And then Use This Code: 
Public Boolean checkWifiConnection(){ 
ConnectivityManager connManager =   
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo mWifi = 
connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWifi.isConnected()) {return true;}
else{return false; }}
 
  OR Next Solution
  

Detect Wifi ON/OFF state 

To detect Android Wifi ON/OFF (Enable/Disable) state, we can implement a BroadcastReceiver to register with the intent WifiManager.WIFI_STATE_CHANGED_ACTION. IN the BroadcastReceiver, the Wifi state can be retrieved using the code intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN).


package com.exercise.AndroidWifiStateChangedDetect;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidWifiStateChangedDetect extends Activity {

TextView WifiState;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      WifiState = (TextView)findViewById(R.id.wifistate);
    
      this.registerReceiver(this.WifiStateChangedReceiver,
              new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));
  }

  private BroadcastReceiver WifiStateChangedReceiver
  = new BroadcastReceiver(){

 @Override
 public void onReceive(Context context, Intent intent) {
  // TODO Auto-generated method stub
 
  int extraWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE ,
    WifiManager.WIFI_STATE_UNKNOWN);
 
  switch(extraWifiState){
  case WifiManager.WIFI_STATE_DISABLED:
   WifiState.setText("WIFI STATE DISABLED");
   break;
  case WifiManager.WIFI_STATE_DISABLING:
   WifiState.setText("WIFI STATE DISABLING");
   break;
  case WifiManager.WIFI_STATE_ENABLED:
   WifiState.setText("WIFI STATE ENABLED");
   break;
  case WifiManager.WIFI_STATE_ENABLING:
   WifiState.setText("WIFI STATE ENABLING");
   break;
  case WifiManager.WIFI_STATE_UNKNOWN:
   WifiState.setText("WIFI STATE UNKNOWN");
   break;
  }
 
 }};
}

 

Update a Database in Android Application

Update a Database in Android Application

When you need to modify a subset of your database values, use the update() method.
Updating the table combines the content values syntax of insert() with the where syntax of delete().


SQLiteDatabase db = mDbHelper.getReadableDatabase();
// New value for one column
ContentValues values = new ContentValues();
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE, title);
// Which row to update, based on the ID
String selection = FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID + " LIKE ?";
String[] selectionArgs = { String.valueOf(rowId) };
int count = db.update(
    FeedReaderDbHelper.FeedEntry.TABLE_NAME,
    values,
    selection,
    selectionArgs);