This configures the permissions for services, private activities and broadcast-protected Intents to be started via Intent from e.g. a notification or another app, even if your app is not currently running. Hence the PendingIntent static methods: getService(), getActivity() or getActivities() and getBroadcast(). Each method requires 4 parameters e.g. for getActivity():
- context: The Context in which this PendingIntent should start the activity
- requestCode: Private request code for the sender, unique to this Intent
- intent: Intent of the activity to be launched
- flags: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens
A PendingIntent can be st up as follows:
private static final int PENDING_INTENT_ID = 58; // Provide unique ID no. for the PendingIntent private static PendingIntent contentIntent (Context context) { // In this case we've set up a helper class Intent intent = new Intent(context, MainActivity.class); // Create the Intent - this opens the MainActivity return PendingIntent.getActivity(context, PENDING_INTENT_ID, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Creates the PendingIntent }
