in my app, have a link to redirect to another app. for example Youtube. i will redirect user to Youtube App using Youtube App Id
.google.android.youtube
however, it will redirect to Google Play Store instead of opening Youtube App. even i have installed the app in my phone. how can i achieve this?
in my app, have a link to redirect to another app. for example Youtube. i will redirect user to Youtube App using Youtube App Id
https://play.google/store/apps/details?id=com.google.android.youtube
however, it will redirect to Google Play Store instead of opening Youtube App. even i have installed the app in my phone. how can i achieve this?
Share Improve this question asked Nov 20, 2024 at 9:02 Shah AmirShah Amir 231 gold badge1 silver badge4 bronze badges 1- How are you using the Link? Have you tried using an Intent? related: stackoverflow/questions/19116634/… – Winter Commented Nov 20, 2024 at 9:19
2 Answers
Reset to default 1If you wanted to redirect user to another application installed in the device, you must need to use the LaunchIntentForPackage
rather then opening any link that you are doing. You are opening play store link of youtube which obviously redirect user to the play store instead you can use the code below to perform the same
val intent = packageManager.getLaunchIntentForPackage("com.google.android.youtube")
if (intent != null) {
// YouTube app is installed, launch it
startActivity(intent)
} else {
// YouTube app is not installed, open Play Store
val playStoreIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google/store/apps/details?id=com.google.android.youtube"))
startActivity(playStoreIntent)
}
If condition will check whether the app where you are redirecting user to is installed in the device or not, if so then it will open the application using application id or package name else it will open the play store link of the provided application.
Use intent, the destination app should accept the URL
this is the "Deep-link"
<activity
android:name="com.example.android.GizmosActivity"
android:label="@string/title_gizmos" >
<intent-filter android:label="@string/filter_view_http_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.example/gizmos” -->
<data android:scheme="http"
android:host="www.example"
android:pathPrefix="/gizmos" />
<!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
<intent-filter android:label="@string/filter_view_example_gizmos">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "example://gizmos” -->
<data android:scheme="example"
android:host="gizmos" />
</intent-filter>
</activity>
to receive parameters in Activity/Fragment:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
val action: String? = intent?.action
val data: Uri? = intent?.data
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742369997a4431073.html
评论列表(0条)