Reputation: 13
I'm having trouble sending and receiving an intent. The relevant code is below... I can't find anything wrong with it. I'm not positive what to put there... Right now the intent is broadcasted and the receiver never catches the permissions one. The Sms works fine however. Could it possibly be the manifest? I'm thinking it has something to do with the action...
PS. I know the spelling mistake in my naming... lol
In a service:
public final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
textFilter = new IntentFilter(SMS_RECEIVED);
textFilter.addAction("ADD_NUMBER_TO_PERMISSIONS");
registerReceiver(incomingReciever,textFilter);
BroadcastReceiver incomingReciever = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent _intent) {
if(_intent.getAction().equals(SMS_RECEIVED)) {
//do some stuff
}
if(_intent.getAction().equals("ADD_NUMBER_TO_PERMISSIONS")) {
//do some stuff
}
}
}
};
Then in a different activity.
Intent resultIntent = new Intent("ADD_NUMBER_TO_PERMISSIONS");
resultIntent.putExtra("NameAndNumber", contact);
setResult(Activity.RESULT_OK, resultIntent);
sendBroadcast(resultIntent);
Upvotes: 1
Views: 389
Reputation: 5759
Make sure you are registering your broadcast in onResume() and unregistering it in onPause() of your activity.
Also you may need the following code after in your manifest.
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
Upvotes: 1