标签:
最近公司有个需求,点击第三方APP的H5页面然后直接跳转到APP里面,比如浏览器打开一个H5页面,然后点击某个链接就直接到APP的某个指定的Activity,经过研究发现实现还是蛮easy的,下面说下方法吧。
首先,在AndroidManifest.xml里面进行配置,在对应的Activity加上一个intent-filter, 如下:
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="paraches" /> </intent-filter> </activity> </application>
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent = getIntent(); String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { Uri uri = intent.getData(); if (uri != null) { String host = uri.getHost(); String dataString = intent.getDataString(); String id = uri.getQueryParameter("id"); String path = uri.getPath(); String path1 = uri.getEncodedPath(); String queryString = uri.getQuery(); Log.d("Alex", "host:"+host); Log.d("Alex", "dataString:" + dataString); Log.d("Alex", "id:" + id); Log.d("Alex", "path:" + path); Log.d("Alex", "path1:" + path1); Log.d("Alex", "queryString:" + queryString); } } }
host:schemedemo dataString:paraches://schemedemo/get/info?id=10000 id:10000 path:/get/info path1:/get/info queryString:id=10000
<a href="paraches://schemedemo/get/info?id=10000">open android app</a>
经过以上步骤就OK了,是不是很easy啊,不过我相信可能还是有小伙伴会迷路,这里上传一下项目demo,这个网页就自己建立了,我就不上传了,链接如下:
http://download.csdn.net/detail/msn465780/9516335
android:scheme 通过uri跳转到APP应用指定Activity
标签:
原文地址:http://blog.csdn.net/msn465780/article/details/51372120