2017-10-05 96 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> 

而是该主机名的变化,以满足自己的喜好,你可以用自己的方式为好。

相关问题