I'm developing a sms application and i'm not able to receive the "SENT" intent if i'm passing MessageURI as data in the intent for a SMS.No Exception is occurred and the sms is in queued status.OnReceive
is not invoked!!!
public class Sms_SendActivity extends Activity {
PendingIntent sentPI;
String Sent = "SENT_SMS";
BroadcastReceiver br;
Button btnSend;
Context mcontext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri uri = Uri.parse("Content://sms/2");
mcontext = getApplicationContext();
sentPI = PendingIntent.getBroadcast(this,0,new Intent(Sent,uri),0);
btnSend = (Button)findViewById(R.id.send);
br = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.w("Check","Inside On Receiver");
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(mcontext,"Inside Sms sent", Toast.LENGTH_SHORT).show();
Log.w("Check"," URI "+intent.getData().toString());
break;
default:
Toast.makeText(mcontext,"failure", Toast.LENGTH_SHORT).show();
break;
}
unregisterReceiver(br);
}
};
btnSend.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage("1-212-555-1212", null, "Hi there", sentPI, null);
Log.w("Check","Sms Queued");
try {
registerReceiver(br, new IntentFilter(Sent,"content://sms"));
} catch (MalformedMimeTypeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
Could u pls help me !!!
Thanks