How to create two entry points to application using deeplink?

我的梦境 提交于 2019-12-24 09:49:42

问题


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.

I tried to use the deeplink to open the second entry point using adb, however I keep getting

Activity not started, unable to resolve Intent.

Here is my manifest file:

<?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();
    }
}

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

Help will be much appreciated.


回答1:


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

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;

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();
    }




}

}



来源:https://stackoverflow.com/questions/50270964/how-to-create-two-entry-points-to-application-using-deeplink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!