2

I have been trying to open my app when user clicks on a link in browser. I tried to use scheme to open my app. The change I made in Manifest is given below.

<activity
        android:name="com.test.testapp.TestAppActivity"
        android:label="@string/app_name"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
           <data android:scheme="testscheme" />
           <action android:name="android.intent.action.VIEW" />
           <category android:name="android.intent.category.BROWSABLE" />
           <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

I also have internet permission added. However opening links like "testscheme://testID=1" do not open up my app. Am I missing something here? I cannot find a solution for this anywhere. Please help.

gunar
  • 14,660
  • 7
  • 56
  • 87
glo
  • 1,408
  • 3
  • 25
  • 54

1 Answers1

0

I tried to reproduce your issue and I couldn't. Here's what I have:
A. An activity with a very simple layout (only a TextView)

package com.test.testapp;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

import com.example.adip.R;

public class TestAppActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.web_layout);
        TextView txtLabel = (TextView) findViewById(R.id.txtLabel);
        Intent startIntent = getIntent();
        Uri data = startIntent.getData();
        if (data == null) {
            txtLabel.setText("No data provided!");
        } else {
            txtLabel.setText(data.toString());
        }
    }
}

B The Manifest contains what you have:

<activity
    android:name="com.test.testapp.TestAppActivity"
    android:exported="true"
    android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <data android:scheme="testscheme" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>

C. A sample.html file that I published on a local Tomcat web server.

<html>
    <body>
        <a href="testscheme://testID=1">Test scheme</a> <br/>
        <a href="http://www.stackoverflow.com">Working link to SO</a>
    </body>
</html>

When opening this file from ANY BROWSER both links work as:

  1. The first link opens the TestAppActivity showing in the TextView: testscheme://testID=1 - exactly what I have in html
  2. The second link opens the good-old StackOverflow in the same browser.

You must be doing something wrong and it's that small you can't see it :). Maybe you have typed incorrectly the link in html file ...

Anyway, make a compare between what I have provided and what you have.

gunar
  • 14,660
  • 7
  • 56
  • 87