Android 应用 A 可以上网:
<uses-permission android:name="android.permission.INTERNET"/>
应用 B 无法访问 Internet。所以我想通过 a 为应用程序 A 提供互联网访问权限到应用程序PendingIntent
B。这是PendingIntent
为了什么,不是吗?
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).
这就是我发送PendingIntent
应用程序 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) { }
这就是我尝试在应用程序 B(具有 launchMode=singleTask)中接收它的方式:
@Override
protected void onNewIntent(Intent i) {
setIntent(i);
// do some things with Internet access here
}
但它不起作用!你知道为什么吗?我做错什么了?
提前致谢!