1

I want to open my application on link click instead of the browser if the application is installed on the device , and open Google play otherwise. so after searching .. This is my manifest

    <activity
        android:name="example.com.MyActivity"
        android:label="@string/title_activity_open_event_details" >
        <intent-filter>
            <data
                android:host="play.google.com"
                android:scheme="http"/>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />


        </intent-filter>
    </activity>

and this is my activity

    public class MyActivity extends Activity {

private int EventId;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_open_event_details);

    tv = (TextView) findViewById(R.id.testtv);

    Uri data = getIntent().getData();
    if ( data != null )
    {
        String scheme = data.getScheme();
        String host = data.getHost(); 
        List<String> params = data.getPathSegments();
        String first = params.get(0); 
        String second = params.get(1); 

        int size = params.size();
    //  EventId  = params.get(size-1);
        String third = params.get(size-1);
        tv.setText(data.toString());
    }


  }


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.my_activity, menu);
    return true;
}

}

when I click on this link https://play.google.com/store/apps/details?id=example.com&evid=117 MyActivity opens successfully but the link that appears in the textview is only https://play.google.com/store/apps/details?id=example.com without &evid=117 which I need to get some data and display it in my activity

could you please help me to know what I am missing ? Thanks in advance

1
  • What happens if user has selected the browser as default app to open the urls ? Commented Feb 10, 2015 at 4:54

1 Answer 1

1

To get that id try this code:

    Uri data = getIntent().getData();
    if (data != null) {
        String url = data.toString();
            try {
                List<NameValuePair> params = URLEncodedUtils.parse(new URI(url), "UTF-8");
                for (NameValuePair para : params)
                    if (para.getName().equals("evid")) {
                        String id = para.getValue(); //my id (117)
                        Log.v("myId",id);
                    }
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }

        }

Also you are not including the https protocol. Add

<data android:host="play.google.com" android:scheme="https"/>

EDIT

I've tested this code and it's working. I've created a simple activity with the code I provided above and for the intent filter:

<intent-filter>
       <action android:name="android.intent.action.MAIN" />

       <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <action android:name="android.intent.action.VIEW"/>
        <data android:host="play.google.com" android:scheme="http"/>
        <data android:host="play.google.com" android:scheme="https"/>
 </intent-filter>

The output result is, as expected, 117

Sign up to request clarification or add additional context in comments.

13 Comments

Thanks for your answer .. but my problem is the url I receive in the activity doesn't contain the "&evid=117" part .. when I debug I see that the url is only [link]play.google.com/store/apps/details?id=example.com I don't know why the url should be [link]play.google.com/store/apps/details?id=example.com&evid=117
Have you tried the code? Also did you tried printing url on my example to see the full url?
Yes I have .. and the url is the same
I updated my answer. And the code is working for me by the way.
I still have the same problem .. I always receive the url without the part of "&evid=117" although I am sure that the link I click on contains this part at the end of the url.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.