简体   繁体   English

Android从其他Android应用程序链接到自己的应用程序

[英]Android link to own applications from other Android applications

i'm trying to have ability like with internal links such as Google market as : 我正在尝试像Google市场这样的内部链接具有以下能力:

market://details?id=de.schildbach.oeffi

for exampele 例如

myApplication://detail?id=11

how to change manifest or create other ability for application to have that? 如何更改清单或创建其他应用程序具有的能力? i want to create link as myApplication://detail?id=11 and share that in other android application such as Telegram or Whatsapp, user can be going to my application after click on my created link. 我想创建链接为myApplication://detail?id=11并在其他Android应用程序(例如Telegram或myApplication://detail?id=11共享该链接,在单击我创建的链接后,用户可以转到我的应用程序。

Add an intent filter to your activity: 向活动添加意图过滤器:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="myApplication"
                android:host="detail"
                />
        </intent-filter>

And then handle the link on your activity's onCreate(..) or onNewIntent(..) 然后处理活动的onCreate(..)或onNewIntent(..)上的链接

    Uri intentData = intent.getData();
    if (intentData != null && "myApplication".equals(intentData.getHost()) && "detail".equals(intentData.getScheme()) {
        //link was clicked, parse the rest of intent's data and do something useful
    }

You have to set a "scheme" as one of the intent_filter of the activity you want to be started, in your Manifest, something like: 您必须在清单中将“方案”设置为要开始的活动的intent_filter之一,例如:

<data android:scheme="@string/deeplink_scheme" />

You can follow Android documentation about it here : Allowing Other Apps to Start Your Activity 您可以在此处遵循Android文档进行操作: 允许其他应用开始您的活动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM