Sunday, August 12, 2012

My Favorite 10 Android Applications

Here i am sharing my favorite 10 android applications,
1. Flipboard

http://market.android.com/search?q=pname:flipboard.app )  My favorite daily using application for reading news, looking facebook, twitter & linkedin updates and viewing blog posts. Very attractive UI design & simple to use.

Thursday, June 21, 2012

Service...?

A service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. Additionally, a component can bind to a service to interact with it and even perform interprocess communication (IPC). For example, a service might handle network transactions, play music, perform file I/O, or interact with a content provider, all from the background

View..?

View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). All of the views in a window are arranged in a single tree. You can add views either from code or by specifying a tree of views in one or more XML layout files. There are many specialized subclasses of views that act as controls or are capable of displaying text, images, or other content.
The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of:

  • an exact number
  • MATCH_PARENT, which means the view wants to be as big as its parent (minus padding)
  • WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding).
  • Example For ListView Using BaseAdapter

    Above is an example of ListView in android which extends BaseAdapter. Here we are inflating Layout to ListView.

    Code:
    public class ListExample extends ListActivity {

    private ArrayList<String> dataname = new ArrayList<String>();
    private ArrayList<String> datacode = new ArrayList<String>();
    Context con = this;

    Wednesday, June 13, 2012

    DDMS..?

    Dalvik Debug Monitor Service, a GUI debugging application shipped with
    the SDK. It provides screen capture, log dump, and process examination
    capabilities

    Intent..?

    A class (Intent) describes what a caller desires to do. The caller
    sends this intent to Android's intent resolver, which finds the most
    suitable activity for the intent. E.g. opening a PDF file is an
    intent, and the Adobe Reader is the suitable activity for this inten

    Android application package file (APK)

    Android application package file (APK) is the file format used to
    distribute and install application software and middleware onto
    Google's Android operating system. To make an APK file, a program for
    Android is first compiled, and then all of its parts are packaged into
    one file. This holds all of that program's code such as (.dex files),
    resources, assets, certificates, and manifest file. As is the case
    with many file formats, APK files can have any name needed, but must
    end with the four character, three letter extension, .apk.[1][2][3][4]
    APK files are ZIP file formatted packages based on the JAR file format.

    Android Debug Bridge

    Android Debug Bridge, a command-line debugging application shipped with the SDK. It provides tools to browse the device, copy tools on the device, and forward ports for debugging. Android Debug Bridge. A tool used to connect and sends commands to your Android phone from a desktop or laptop computer.

    Android Application Architecture

    1. Services - like Network Operation
    2. Intent - To perform inter-communication between activities or services
    3. Resource Externalization - such as strings and graphics
    4. Notification signaling users - light, sound, icon, notification, dialog etc.
    5. Content Providers - They share data between applications

    Thursday, May 17, 2012

    Example 2:

    Example 2:

    Continuation of Example 1,

    Add one more button to main.xml layout and name it as Activity.
    Then add another layout called activity1.xml, For that right click on the layout folder --> new --> Android Xml File

    Wednesday, May 16, 2012

    Example 1:

    Example 1:

    Open 'main.xml' from layout folder.
    Then from toolbox add,
    1.EditText
    2.Button
    And rename the button by right clicking on the button and select 'Edit text..' to 'Done'



    First Project in Android

    First Project in Android

    1. Goto Eclipse,then
    2. File --> New--> Android Project
    3. Project Name : MyFirstAndroidProject (Create new Project in workspace) ,Then Next,
    4. Check Android2.2 and next
    5. Don't Change Application name,
       Package name : com.jeeth.examples.myfirstandroidproject
       Then Press Finish.


    Tuesday, May 15, 2012

    Setup Android SDK and Eclipse IDE for Android Application Development

    First, Setuping IDE for Android Development

    1.Download Eclipse IDE for Java Developers http://www.eclipse.org/downloads/packages/release/helios/sr2
    2.Download Android sdk and install. http://developer.android.com/sdk/index.html
    (It may take 2 or more hours to finish the installation)
    3.Ten unzip the eclipse file. Then execute it.
    4.After that goto Help in eclipse, and Select Install new softwares. Then select 'Add'.
    (Name : Android
    Then Press Ok.

    Monday, May 7, 2012

    Creating Notification in Android


    Here is a code for creating notification for your application. Copy the below code to your project, 

    private void createNotification(String tickerText, String contentTitle,
    String contentText, int notiIcon) {
    String notiservice = Context.NOTIFICATION_SERVICE;
    NotificationManager notimanager = (NotificationManager) getSystemService(notiservice);

    int icon = notiIcon;
    CharSequence tickerText = tickerText;
    long when = System.currentTimeMillis();
    Context context = getApplicationContext();
    CharSequence contentTitle = contentTitle;
    CharSequence contentText = contentText;

    Intent notiIntent = new Intent(this, Options.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0,
    notiIntent, 0);

    Notification notification = new Notification(icon, tickerText, when);
    notification.setLatestEventInfo(context, contentTitle, contentText,
    pIntent);

    final int ID = 1;
    notimanager.notify(ID, notification);
    }

    And then call it with following parameters,
    createNotification("My Notification", "Jimmanz", "Notification Started",
    R.drawable.icon);

    Shake effect in Android

    Shake effect in Android

    We can give shaking effect for any layout component in android.
    For that first we have to create a folder anim under res folder. In anim first create an xml 'cycle_7.xml'
    <?xml version="1.0" encoding="utf-8"?>
    <cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />

    Then create another xml called 'shake.xml'
    <?xml version="1.0" encoding="utf-8"?>
    <translate xmlns:android="http://schemas.android.com/apk/res/android
    android:fromXDelta="0" 
    android:toXDelta="10" 
    android:duration="1000" 
    android:interpolator="@anim/cycle_7" />

    Then in class file,import these two,
    import android.view.animation.Animation;
    import android.view.animation.AnimationUtils;

    Then add this in code,(when and where that you can decide),
    Animation shake = AnimationUtils.loadAnimation(CurrentActivity.this, R.anim.shake);
    findViewById(R.id.textViewShake).startAnimation(shake);

    Now run.............!

    Creating Analog clock Widget in Android


    Creating Analog clock Widget in Android

    Manifest:
    <uses-sdk android:minSdkVersion="7" />


    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:name=".JeethClockActivity"
            android:label="@string/app_name" >
            
        </activity>


        <receiver
            android:name=".WidgetClockClass"
            android:label="CR CLOCK" 
            android:icon="@drawable/icon">>
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/jeethappwidget" />
        </receiver>
    </application>

    No need of programing in WidgetClockClass.class,
    import android.appwidget.AppWidgetProvider;


    public class WidgetClockClass extends AppWidgetProvider {


    }

    Create a folder 'xml' in res folder, then inside that create an xml for appwidget provider,
    <?xml version="1.0" encoding="utf-8"?>
    <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
    android:updatePeriodMillis="1000" 
    android:minWidth="100dp" 
    android:minHeight="100dp" 
    android:initialLayout="@layout/clock">
    </appwidget-provider>


    Then create a layout called clock.xml in layout folder,
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical" >


        


        <AnalogClock
            android:id="@+id/analogClock2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


    </LinearLayout>

    Tracking call from a particular number in Android


    Tracking call from a particular number in Android

    Here manifest looks like,
    <uses-permission android:name="android.permission.READ_PHONE_STATE" >
    </uses-permission>
    <receiver
    android:name="ReceiveCallToMute"
    android:permission="android.permission.READ_PHONE_STATE" >
    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE" >
        </action>
    </intent-filter>
    </receiver>

    And broadcast receiver will invoked when a call comes,
    For a call, there are three states,
    1. Ringing
    2. Idle
    3. Offhook

    public class ReceiveCallToMute extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
      Bundle b=intent.getExtras();
      if(b!=null){
      String state=b.getString(TelephonyManager.EXTRA_STATE);
      String number=b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
      if(number.indexOf("9447024365") != -1) {
      if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
      
      }else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
      
      }else if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){  
      
      }
      }
      }
    }
    }

    Sunday, May 6, 2012

    Deleting an sms from a particular number in Android


    For deleting an sms from a particular number.
    Here we have to use a Broadcast receiver. When an sms is receiving, this broacast receiver will invoked.
    So our manifest will look like this,

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />

    <receiver android:name="Receiverdetectsms" android:permission="android.permission.BROADCAST_SMS" >
    <intent-filter android:priority="999" >
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>


    And (Broadcast receiver) "Receiverdetectsms"  will look like,
    public class Receiverdetectsms extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    SmsMessage[] msgs = null;
    if (bundle != null) {
    /* Retrieve the SMS. */
    Object[] pdus = (Object[]) bundle.get("pdus");
    msgs = new SmsMessage[pdus.length];
    for (int i = 0; i < msgs.length; i++) {
    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
    if (msgs[i].getOriginatingAddress().indexOf("9447024365") != -1) {
    abortBroadcast();//delete sms from 9447024365
    }
    }
    }
    }

    }


    Async Task in Android


    Here in asynctask, there are some overrided functions,
    1. doInBackground
    2. onPreExecute(execute before doInBackground)
    3. onPostExecute(execute after doInBackground)
    4. onProgressUpdate(doInBackground can call this function while its executing using  'publishProgress(integer value)'. Mainly for showing progress bar while downloading or uploading something)

    private class SyncIncoData extends AsyncTask<String, String, String> {
    ProgressBar pb;
    ProgressBar pbar;

    @Override
    protected String doInBackground(String... urls) {
    for (int i = 0; i <= 100; i++) {
    publishProgress(i);
    }
    return null;
    }

    @Override
    protected void onPreExecute() {

    super.onPreExecute();

    pb = (ProgressBar) findViewById(R.id.progressBarsync4);
    pb.setVisibility(View.VISIBLE);

    }

    @Override
    protected void onPostExecute(String result) {

    pb = (ProgressBar) findViewById(R.id.progressBarsync4);
    pb.setVisibility(View.INVISIBLE);

    }

    @Override
    protected void onProgressUpdate(String... values) {
    pbar = (ProgressBar) findViewById(R.id.progressBarpbar);
    pbar.setProgress(Integer.parseInt(values[0]));
    super.onProgressUpdate(values);
    }
    }


    For calling async task,
    SyncIncoData task = new SyncIncoData();
    task.execute(new String[] { null });