2016-01-13 93 views
0

我在帖子中看到了How to open an application inside another application within the latters boundaries in android?使用自定義URL方案啓動另一個應用程序會在啓動應用程序的邊界內打開應用程序。

但是,當我嘗試使用自定義URL方案打開另一個應用程序時,它發生在我的應用程序中。有誰知道爲什麼會發生這種情況?

調用其他應用程序的代碼如下。

String callBackUrl = 「OtherApp://result?params」; // This is supposed to be a callback URL with query parameters 
String redirectUrl = callBackUrl.substring(0, callBackUrl.indexOf("://")); 
Intent redirectIntent = new Intent(); 
redirectIntent.putExtra(Intent.EXTRA_TEXT, callBackUrl); 
redirectIntent.setAction(redirectUrl); 
redirectIntent.setType("text/plain"); 
startActivity(redirectIntent); 

回答

0

原因是因爲我的應用程序是一個單一的任務應用程序。它是我Activity元素的AndroidManifest.xml中的android屬性。

 android:launchMode="singleTask" 

我找到的解決方案是添加兩個標誌到「redirectIntent」。

 redirectIntent.setFlags(Intent.URI_INTENT_SCHEME); 
     redirectIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
相關問題