簡體   English   中英

如何在我的 Android 應用程序中打開來自其他應用程序的鏈接

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

我想在我的應用程序中打開一個外部鏈接。

例如,當用戶從 instagram 點擊www.example.com/batmanpage ,我想在我的應用程序中打開這個頁面(蝙蝠俠頁面),作為一個深層鏈接。

我該怎么做?

只需谷歌“Android 深層鏈接”。 你會得到例如:

這個鏈接

請注意細節,否則您的深層鏈接將不起作用。

<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>

在活動中,您需要從意圖中讀取值:

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

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

如果您的 Activity 不是“標准”並且已經創建了一個實例,您將在onNewIntent方法中收到意圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM