Open specific activity from url

 ̄綄美尐妖づ 提交于 2019-12-22 14:56:13

问题


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:


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


来源:https://stackoverflow.com/questions/21470794/open-specific-activity-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!