Intent and Broadcast Receiver trouble
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);
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>
精彩评论