Posts

Showing posts from May, 2012

Example 2:

Image
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

Example 1:

Image
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

Image
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.

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 Location : http://dl-ssl.google.com/android/eclipse/)  Then Press Ok.

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", &q…

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)…

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 App…

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…

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"); msg…

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.progressBarp…