Thursday, April 19, 2012

Sending SMS programatically

There are two ways to send sms in android

1.Using smsManager
2.Using Intent

1.Using smsManager
private void sendSMS(String phoneNumber, String message)
    {        
        PendingIntent pi = PendingIntent.getActivity(this, 0,
 new Intent(this, SMS.class), 0);                
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, pi, null);        
    } 
 Add this permission in manifest file 
<uses-permission android:name="android.permission.SEND_SMS">
 
2.Using Intent 
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
       sendIntent.putExtra("sms_body", "Content of the SMS goes here..."); 
       sendIntent.setType("vnd.android-dir/mms-sms");
       startActivity(sendIntent); 
 
 
You can get more details from the following site
http://mobiforge.com/developing/story/sms-messaging-android
   
 

Tuesday, April 17, 2012

Content Provider and Content Resolver

A ContentProvider is a generic mechanism for an application to provide
access to data. This is done by subclassing ContentProvider,
implementing certain methods, and publishing information in the manifest.

To access data provided by ContentProvider(s), you use ContentResolver.
There is no need to subclass.

http://developer.android.com/guide/topics/providers/content-providers...

This mechanism is used in certain Google applications.

Some of those, but not all, are considered to be part of the SDK, and
can be used by other applications as well:

http://developer.android.com/reference/android/provider/package-summa...

Some others are internal, and should not be used by other applications.

These internal providers can change at any time: with a new Android
release, a new version of a Google application, or even when Android is
customized by a device manufacturer.

These include Calendar and GMail, and perhaps more. It's not a good idea
to use them in your application.

If you do, and make it work somehow, be aware that your code can break
at any time.

Friday, April 13, 2012

Calling finish() on an Android activity doesn't actually finish

You should put a return statement after that finish, because the method that called finish will be executed completely otherwise.
 
The method that called finish() will run to completion. The finish() operation will not even begin until you return control to Android.

suppose you have a method xyz like below

xyz()
{
statment1
statement2
.
.
finish();
statement6
statement7
}

Then the finish() function will be called after statement7 is executed and the control has returned to android.

So , if you want your app to finish() immediately then put a return statement after finish(), Like below
xyz()
{
statment1
statement2
.
.
finish();
return;
statement6
statement7

}

Statement6 and statement7 will not be executed any more