Open specific activity from url

2019-07-20 05:31发布

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?

1条回答
叛逆
2楼-- · 2019-07-20 05:59

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();
查看更多
登录 后发表回答