[英]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:你会得到例如:
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.