pramod.deore
Newbie
In my application I am sending a sms programatically, when I ran the application it send sms but on Logcat file it throws following exception
The method which send sms is as follows
Thanks
Code:
02-07 12:38:15.447: ERROR/ActivityThread(839): Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$1@435a0c70"]com.micro.MyTest$1@435a0c70[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
02-07 12:38:15.447: ERROR/ActivityThread(839): android.app.IntentReceiverLeaked: Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$1@435a0c70"]com.micro.MyTest$1@435a0c70[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:707)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:535)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:748)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:735)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:729)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:278)
02-07 12:38:15.447: ERROR/ActivityThread(839): at com.micro.MyTest.sendSMS(MyTest.java:98)
02-07 12:38:15.447: ERROR/ActivityThread(839): at com.micro.MyTest.onCreate(MyTest.java:42)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.os.Looper.loop(Looper.java:123)
02-07 12:38:15.447: ERROR/ActivityThread(839): at android.app.ActivityThread.main(ActivityThread.java:3948)
02-07 12:38:15.447: ERROR/ActivityThread(839): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 12:38:15.447: ERROR/ActivityThread(839): at java.lang.reflect.Method.invoke(Method.java:521)
02-07 12:38:15.447: ERROR/ActivityThread(839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
02-07 12:38:15.447: ERROR/ActivityThread(839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
02-07 12:38:15.447: ERROR/ActivityThread(839): at dalvik.system.NativeStart.main(Native Method)
02-07 12:38:15.496: ERROR/ActivityThread(839): Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$2@435a13b8"]com.micro.MyTest$2@435a13b8[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
02-07 12:38:15.496: ERROR/ActivityThread(839): android.app.IntentReceiverLeaked: Activity com.micro.MyTest has leaked IntentReceiver [EMAIL="com.micro.MyTest$2@435a13b8"]com.micro.MyTest$2@435a13b8[/EMAIL] that was originally registered here. Are you missing a call to unregisterReceiver()?
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread$PackageInfo$ReceiverDispatcher.<init>(ActivityThread.java:707)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread$PackageInfo.getReceiverDispatcher(ActivityThread.java:535)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ApplicationContext.registerReceiverInternal(ApplicationContext.java:748)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:735)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ApplicationContext.registerReceiver(ApplicationContext.java:729)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:278)
02-07 12:38:15.496: ERROR/ActivityThread(839): at com.micro.MyTest.sendSMS(MyTest.java:129)
02-07 12:38:15.496: ERROR/ActivityThread(839): at com.micro.MyTest.onCreate(MyTest.java:42)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.os.Looper.loop(Looper.java:123)
02-07 12:38:15.496: ERROR/ActivityThread(839): at android.app.ActivityThread.main(ActivityThread.java:3948)
02-07 12:38:15.496: ERROR/ActivityThread(839): at java.lang.reflect.Method.invokeNative(Native Method)
02-07 12:38:15.496: ERROR/ActivityThread(839): at java.lang.reflect.Method.invoke(Method.java:521)
02-07 12:38:15.496: ERROR/ActivityThread(839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
02-07 12:38:15.496: ERROR/ActivityThread(839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
02-07 12:38:15.496: ERROR/ActivityThread(839): at dalvik.system.NativeStart.main(Native Method)
The method which send sms is as follows
Code:
[SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sendSMS(String phoneNumber, String message)
{
String SENT = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS_SENT"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
String DELIVERED = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS_DELIVERED"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
PendingIntent sentPI = PendingIntent.[I]getBroadcast[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 0,[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.[I]getBroadcast[/I]([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], 0,[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(DELIVERED), 0);
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---when the SMS has been sent--- [COLOR=red]Following line throws Exception (it is line no 98[/COLOR][/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]registerReceiver([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BroadcastReceiver(){
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onReceive(Context arg0, Intent arg1)
{
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (getResultCode())
{
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_OK[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS Sent"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_GENERIC_FAILURE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Generic failure"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_NO_SERVICE[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"No service"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_NULL_PDU[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Null PDU"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SmsManager.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_ERROR_RADIO_OFF[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Radio off"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
}
}, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IntentFilter(SENT));
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//---when the SMS has been delivered---[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]registerReceiver([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] BroadcastReceiver()
{
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onReceive(Context arg0, Intent arg1)
{
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]switch[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (getResultCode())
{
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_OK[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS Delivered"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Activity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]RESULT_CANCELED[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
Toast.[I]makeText[/I](getBaseContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"SMS not delivered"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_SHORT[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]break[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
}
},[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] IntentFilter(DELIVERED));
SmsManager sms = SmsManager.[I]getDefault[/I]();
sms.sendTextMessage(phoneNumber, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], message, sentPI, deliveredPI); [/LEFT]
}
[/SIZE]
Thanks