简体   繁体   中英

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.

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.

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




}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM