I'm trying out to enforce broadcaster permissions in my application. The
scenario is that I have an activity A, which triggers a broadcasts like
this (with a permission) :
Intent updateUserBroadcast = new Intent();
updateUserBroadcast.setAction("android.intent.action.ACTION_UPDATE_USERNAME");
updateUserBroadcast.putExtra("username", userName);
sendBroadcast(updateUserBroadcast,
"com.android.MaliciousApp.RECEIVE_BROADCAST");
In this activity A, I register a receiver in onCreate like this :
registerReceiver(mUpdateUsernameReceiver, new
IntentFilter("android.intent.action.ACTION_UPDATE_USERNAME"),
"com.android.MaliciousApp.RECEIVE_BROADCAST", null);
The receiver is defined as a private variable in the activity A as :
private BroadcastReceiver mUpdateUsernameReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.v("gaurav", "onReceive called");
SharedPreferences prefs = context.getSharedPreferences("profilePref",
Context.MODE_WORLD_READABLE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("username", intent.getStringExtra("username"));
editor.apply();
Toast.makeText(context,
context.getString(R.string.string_successfully_updated),
Toast.LENGTH_SHORT).show();
}
};
I expect the receiver to receive the broadcast as it has the required
permissions that it needs. But it doesn't receive the broadcast sent out by
the activity. There could be arguments on why I'm not using
LocalBroadcastManager, but my motive is to figure out why this method isn't
working as expected.
I have not declared my receiver in manifest and registering it dynamically
only. All the above code is from a single activity within the same
application. So there's no IPC involved here, just a simple example to
check out the permissions. Any help would be appreciated.
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/a15e7ace-5ab7-412d-85fa-ea21acd7d5a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.