简体   繁体   English

如何在我的 Android 应用程序中打开来自其他应用程序的链接

[英]How can open link from other Apps in my App in Android

I want to open an external link in my app.我想在我的应用程序中打开一个外部链接。

For example when the user clicks on www.example.com/batmanpage from instagram I want to open this page (Batman page) in my application, as a deep link.例如,当用户从 instagram 点击www.example.com/batmanpage ,我想在我的应用程序中打开这个页面(蝙蝠侠页面),作为一个深层链接。

How can I do it?我该怎么做?

Just google "Android deep link".只需谷歌“Android 深层链接”。 You will get for example:你会得到例如:

this link 这个链接

Be careful about the details or your deep link won't work.请注意细节,否则您的深层链接将不起作用。

<activity
    android:name="com.example.android.GizmosActivity"
    android:label="@string/title_gizmos" >
    <intent-filter android:label="@string/filter_title_viewgizmos">
        <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.com/gizmos” -->
        <data android:scheme="http"
              android:host="www.example.com"
              android:pathPrefix="/gizmos" />
        **<!-- note that the leading "/" is required for pathPrefix-->**
        <!-- Accepts URIs that begin with "example://gizmos” -->
        <data android:scheme="example"
              android:host="gizmos" />

    </intent-filter>
</activity>

In the activity you need to read the values from the intent:在活动中,您需要从意图中读取值:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    String action = intent.getAction();
    Uri data = intent.getData();
}

If your Activity is not "standard" and if an instance has already been created you will receive the intent in the onNewIntent method.如果您的 Activity 不是“标准”并且已经创建了一个实例,您将在onNewIntent方法中收到意图。

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

相关问题 如何从Android应用程序打开智能手机上的其他应用程序(全部) - How to open other apps (all) on the smart phone ,from an android app 如何从其他应用程序启动我的 Flutter 应用程序 - How can I Launch My Flutter App from other Apps 如何使用自定义链接打开我的 Android 应用程序? - How can I open my Android app with a custom link? 我的Phonegap-App如何在Android浏览器中打开链接? - How can my Phonegap-App open a Link in the Android Browser? 如果仅登录到其他应用,请从其他应用打开我的应用 - open my app from other apps if only logged in to the app Android Cordova-即使其他应用已打开,切换回我的应用 - Android Cordova - switch back to my app even if other apps are open 从我的应用程序和仅我的应用程序启动其他 Android 应用程序 - Launching other Android apps from my app and only my app 如何在我的应用程序中隐藏其他应用程序? - How to Hide other apps from my app? 如何通过单击其他已安装应用中的任何按钮来打开我的应用 - how to open my app by clicking any button in other installed apps 如何从我的 webview 应用程序(如 Instagram 等)打开其他应用程序? - How to open other apps from my webview app like Instagram etc?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM