如何使用Deeplink为应用程序创建两个入口点? [英] How to create two entry points to application using deeplink?
问题描述
我想创建一个具有两个入口点的应用程序。
当用户单击应用程序图标时,第一个条目将是常规条目。
第二个将通过将通过推送通知发送的深层链接。
I want to create an application which will have two entry points. The first will be a regular entry when the user clicks the app icon. The second one will be through a deeplink which will be sent through push notifications.
我使用了此教程来建立深度链接。
I used this tutorial to build the deeplink.
我尝试使用deeplink使用adb打开第二个入口点,但是我不断得到
I tried to use the deeplink to open the second entry point using adb, however I keep getting
活动尚未开始,无法解决Intent。
Activity not started, unable to resolve Intent.
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.edwardkeselman.siemens">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Login">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ReportActivity" />
<activity android:name=".DetailsActivity">
<intent-filter>
<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>
</application>
</manifest>
这是我的详细信息活动:
Here is my DetailsActivity:
public class DetailsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
}
}
这是我用来尝试打开DetailsActivity的adb命令:
This is the adb command that I use to try to open the DetailsActivity:
adb shell am start -W -a android.intent.action.BROWSE -d "example://gizmoz" com.example.myname
我们将不胜感激。
推荐答案
manifest.xml
manifest.xml
<activity android:name=".DeepLinking">
<intent-filter android:label="@string/filter_deeplinking">
<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:host="domain.in"
android:scheme="http" />
<!-- 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>
DeepLinking.java
DeepLinking.java
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.net.URLDecoder;
公共类DeepLinking扩展了AppCompatActivity {
public class DeepLinking extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deep_linking);
Intent intent = getIntent();
String action = intent.getAction();
Uri uri_data = intent.getData();
String data=uri_data.toString();
Log.d("DATA : ",""+uri_data.toString());
if(data.equals("domain.in") || data.equals("http://domain.in") )
{
Intent i = new Intent(getApplicationContext(), Splash.class);
startActivity(i);
finish();
}
else if (!data.equals(null))
{
Intent i = new Intent(getApplicationContext(), DetailActivity.class);
startActivity(i);
finish();
}
else
{
Intent i = new Intent(getApplicationContext(), Splash.class);
startActivity(i);
finish();
}
}
}
这篇关于如何使用Deeplink为应用程序创建两个入口点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!