Android app A has Internet access:
<uses-permission android:name="android.permission.INTERNET"/>
App B does not have Internet access. So I want to give Internet access from app A to app B via a PendingIntent. This is what PendingIntent is for, isn’t it?
By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity).
This is how I send the PendingIntent in app A:
Intent mainApp = new Intent(Intent.ACTION_MAIN);
mainApp.addCategory(Intent.CATEGORY_LAUNCHER);
mainApp.setClassName("com.other.package", "com.other.package.MainActivity");
int flags = PendingIntent.FLAG_UPDATE_CURRENT | Intent.FLAG_ACTIVITY_NEW_TASK;
PendingIntent pi = PendingIntent.getActivity(this, 23894729834, mainApp, flags);
try {
pi.send();
}
catch (CanceledException e) { }
And this is how I try to receive it in app B (which has launchMode=singleTask):
@Override
protected void onNewIntent(Intent i) {
setIntent(i);
// do some things with Internet access here
}
But it doesn’t work! Do you know why? What did I do wrong?
Thanks in advance!
That is not possible, sorry.
No.
Let’s look more closely at the portion of the documentation that you quoted:
(boldface mine for emphasis)
App B can execute the
PendingIntentviasend(), and it will run as if App A had executed it, if you were to send thePendingIntentto App B (e.g., as anIntentextra). However:You are having App A execute the
PendingIntentviasend(), starting up App B, rather than sending thePendingIntentto App B.App B does not magically get App A’s permissions, just because it happened to be invoked via some
PendingIntentcreated by App A.There is no way for you to “give Internet access from app A to app B” by any means. App B can ask App A to perform requests upon its behalf (e.g., via commands sent to a service exposed by App A). However, you will want to take great care when doing this, as by default not only will you be able to ask App A to do things, but so can any other app on the device, unless you use a signature-level custom permission to protect App A’s exported service.