0
如何處理任務:打開任務管理器以查看。在同一任務中啓動外部活動
我一直在想,自從很久以前就不可能在當前的任務中開始外部活動。但我發現這是不正確的!
我的應用程序可以在同一個任務中啓動一個twitter/facebook/sms(當點擊任務管理器按鈕時,我只能看到我的任務)。但是這不適用於瀏覽器。我已經嘗試過兩種瀏覽器應用程序Chrome和Firefox。沒有一個像twitter/facebook/sms一樣工作
以下是打開Facebook客戶端和瀏覽器的代碼。任何意見將非常感激!
public Intent shareViaFacebook(Activity ctx) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
ActivityInfo appInfo = searchForApp(ctx, intent, "facebook");
if (appInfo == null)
return null;
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName(appInfo.packageName, appInfo.name));
intent.putExtra(Intent.EXTRA_TEXT, "message");
return intent;
}
public Intent launchBrowser(Activity ctx, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
ActivityInfo appInfo = searchForApp(ctx, intent, null);
if (appInfo == null)
return null;
intent.setComponent(new ComponentName(appInfo.packageName, appInfo.name));
intent.addCategory(Intent.CATEGORY_LAUNCHER);
return intent;
}