Android應用程序可以訪問Internet:提供因特網接入Android應用程序通過的PendingIntent
<uses-permission android:name="android.permission.INTERNET"/>
應用B沒有上網。所以我想通過PendingIntent
從應用程序A訪問應用程序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
:
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
}
但它不起作用!你知道爲什麼嗎?我做錯了什麼?
在此先感謝!