2017-10-05 98 views
0

從我的本機應用程序,我需要打開我的另一個由Ionic構建的應用程序。Andorid,如何使用自定義URL方案打開另一個應用程序?

我試過這樣的,

val intent = packageManager.getLaunchIntentForPackage("com.example.app") 
intent.putExtra("uri", "hello 2?") 
intent.data = Uri.parse("hello?") 
startActivity(intent) 

它可以啓動應用程序,但它從來不叫handleOpenURL()方法。

所以我想嘗試使用自定義URL方案,而不是包名稱。

如何使用帶URI參數的自定義URL方案打開另一個應用程序?

回答

2
Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setData(Uri.parse("YOUR_URL")); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    if (intent.resolveActivity(getPackageManager()) != null) { 
     startActivity(intent); 
    } else { 
     Toast.makeText(this, R.string.no_activity_found, Toast.LENGTH_LONG).show(); 
    } 
+0

它的工作原理!非常感謝! –

+0

您最歡迎的:) – Anonymous

3

這對我有效。在你的Android清單的發射活動提到以下行

<intent-filter> 
     <data android:scheme="http" /> 
     <!-- or you can use deep linking like --> 

     <data android:scheme="http" android:host="abc.xyz"/> 
     <action android:name="android.intent.action.VIEW"/> 
     <category android:name="android.intent.category.BROWSABLE"/> 
     <category android:name="android.intent.category.DEFAULT"/> 

</intent-filter> 

而是該主機名的變化,以滿足自己的喜好,你可以用自己的方式爲好。

相關問題