2

I want open specific activity my app android after click url my website from browser android.

if my url = <a href="http://myapp.com/aa-bb-cc-dd.html"> open activity </a>

and my activity is DetailActivity , how to open this activity after click my url ?

and I want "aa-bb-cc-dd" for setText Textview in DetailActivity .

text1.setText("aa"); text2.setText("bb"); text3.setText("cc"); text4.setText("dd");

How its work?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Amay Diam
  • 2,561
  • 7
  • 33
  • 57
  • have you tried to to use a webView? – Scary Wombat Jan 31 '14 at 01:11
  • no, i want activity without webView, but i will like >> http://stackoverflow.com/questions/1609573/intercepting-links-from-the-browser-to-open-my-android-app but how if implement with my url ... – Amay Diam Jan 31 '14 at 01:15

1 Answers1

16

In your AndroidManifest.xml, declare that your DetailActivity can handle the URL.

<activity
    android:name=".DetailActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSER" />
        <data
            android:scheme="http"
            android:host="myapp.com"/>
    </intent-filter>
</activity>

You can then open up the URL as usual.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://myapp.com/aa-bb-cc.html"));
startActivity(intent);

In your DetailActivity, you can get and parse the URL passed to it as follows.

Uri uri = getIntent().getData();
String path = uri.getPath();
Yuichi Araki
  • 3,438
  • 1
  • 19
  • 24