以下转载自 : http://blog.csdn.net/geekpark/article/details/16118457
为了实现这个功能可折腾了我好久,先上一份代码,经楼主验证是绝对可以用的而且也比较清晰的代码!(ps:还是先剧透下吧,第三方大部分浏览器无法成功。)
点击浏览器中的URL链接,启动特定的App。
首先做成HTML的页面,页面内容格式如下:
<a href="[scheme]://[host]/[path]?[query]">启动应用程序</a>
这一句就可以了。
各个项目含义如下所示:
scheme:判别启动的App。 ※详细后述
host:适当记述
path:传值时必须的key ※没有也可以
query:获取值的Key和Value ※没有也可以
作为测试好好写了一下,如下:
<a href="myapp://jp.app/openwith?name=zhangsan&age=26">启动应用程序</a>
接下来是Android端。
首先在AndroidManifest.xml的MAIN Activity下追加以下内容。(启动Activity时给予)
※必须添加项
<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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/> </intent-filter>
HTML记述的内容加入<data …/>。
其中必须的内容仅scheme,没有其他内容app也能启动。
※注意事项:intent-filter的内容【android.intent.action.MAIN】和 【android.intent.category.LAUNCHER】这2个,不能与这次追加的内容混合。
所以,如果加入了同一个Activity,请按以下这样做,否则会导致应用图标在桌面消失等问题。
<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="myapp" android:host="jp.app" android:pathPrefix="/openwith"/> </intent-filter>
这样的话,没有问题。
接下来在Activity中需要取值的地方添加以下代码,我是直接写在OnCreate函数里的:
String action = i_getvalue.getAction();
if(Intent.ACTION_VIEW.equals(action)){
Uri uri = i_getvalue.getData();
if(uri != null){
String name = uri.getQueryParameter("name");
String age= uri.getQueryParameter("age");
}
}
这样就能获取到URL传递过来的值了。
——————————————————————————————————我是分割线————————————————————————————————————
代码copy完了,是不是很惊奇的发现用浏览器输入
myapp://jp.app/openwith?name=zhangsan&age=26
是不是404,打不开?
楼主你这不是骗人么!楼主你个混蛋啊。
客官,稍安勿躁啊,你看看你用的浏览器是什么?UC,猎豹,欧朋?放弃吧,试试系统自带浏览器或者谷歌浏览器吧。肯定能成功的,不能成功的话再来坑我。哈哈。
——————————————————————————————————我是分割线————————————————————————————————————
突然觉得好悲哀,好不容易get了这个技能,却不能被第三方浏览器使用。在这个android浏览器大部分被第三方占据着的时代不得不说是个悲剧啊。
接下来还是说说为什么第三方浏览器不能成功吧。首先,我发现的是UC浏览器,如果你使用了自己的scheme,而不是http的话,uc会默认在你的scheme前面添加http://。这太坑爹了。其他浏览器没看是不是同样的情况。发现这个问题后我就试着把自己的scheme换成http。然后满怀期待的又跑了一遍,结果还是坑爹了。所以我想会不会是第三方浏览器对url做了处理。到这里,我也无可奈何了。我测试了UC,猎豹,欧朋,这3个都不支持。系统自带的和谷歌浏览器是支持的。
最后再补充个线索吧,在浏览器里搜索百度应用。进了他们的页面后,他们是可以实现在各种浏览器启动已经安装好的本地app的。看到这个后我就看了下他们页面的源码。
在这里他们页面添加了个data-sentintent的标签,看到这里,应该能确定第三方浏览器应该是默认都不支持发intent的,只能自己起一个。根据前端说,这个标签应该是自定义的。我们前端看源码的时候发现是这样的
所以最后的结果应该是百度这边是起了个端口,然后在应用里启用了一个服务,来监听这个端口,来获取这个intent。大概就这个思路了。不过楼主没有实际去操作。项目时间紧,太麻烦了。对了,百度这个是有集成他们inapp这个sdk的。
再附上stackoverflow两个相关链接:http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app
http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser
相关推荐
Yuzu browser is an open source power full web browser. You can create your own browser using custom UI and custom buttons. This browser based on Mikan Browser. Download and install Android 5.0 or ...
Learn the basics for making a web page look great on the Android web browser Convert a website into a web application, complete with progress indicators and more Add animation with jQTouch to make ...
-- delete/rename in file browser -- email as text or attachment -- Search using "search" button NOTES This app currently does everything I need it do. Minus some bug fixes, this is probably it for ...
Learn the basics for making a web page look great on the Android web browser Convert a website into a web application, complete with progress indicators and more Add animation with jQTouch to make ...
2) To install from our site open in Android browser: MyLifeOrganized for Android Installation notes: You can download and install the app using your Android web browser. You will have to enable the ...
Intent App : Simple App to demonstrate the Intent to open web browser. Storage App : Android Storage App using SQLite and Shared Preferences. Services App : Creating and Managing the lifecycle of ...
The biggest feature of Android is its open architecture, which notonly provides an excellent development and debugging environment but alsosupports various extensible user experiences, including rich ...
Advanced native Android schedule browser application for the Capitole du Libre conference in Toulouse, France. How to build All dependencies are defined in app/build.gradle. Import the project in ...
document.getElementById('openInBrowser').addEventListener('click', function() { if (navigator.standalone) { alert('请按右上角“用浏览器打开”'); } else { // 如果不在微信内置浏览器中,则直接打开...
Android, the next-generation open mobile platform from Google and the Open Handset Alliance, is poised to become a significant player in the mobile device market. The Android platform gives developers...
Android SDK tools included in Android 1.1 SDK, Release 1. Supported Supported Supported Supported Operating Operating Operating Operating Systems Systems Systems Systems • Windows XP (32-bit) or ...
Android, the next-generation open mobile platform from Google and the Open Handset Alliance, is poised to become a significant player in the mobile device market. The Android platform gives developers...
A Flutter plugin that allows you to add an inline webview or open an in-app browser window. This plugin is inspired by the popular cordova-plugin-inappbrowser! Requirements Dart sdk: ">=2.1.0-dev.7.1...
目前,Open Two-Factor身份验证器支持桌面上的Firefox,Android,Chrome和Opera浏览器上的Firefox。 独立的Android植入仍在进行中。 要报告错误,请打开新问题: ...
Hews A hacker news reader focuses on readng experience with some handy features. ...Open post/other links in external browser Check User's HN profile (long press) Share comment l
Android Intent 学习笔记
openbrowser 依赖库 compile 'com.android.support:appcompat-v7:24.2.0' compile 'com.android.support:design:24.1.1' compile project(':android-volley') compile files('libs/gson-2.3.1.jar') compile '...
Each social icon is programmed to open in the corresponding app or in the browser if the app isn't present. Including this library into your preference screen layout is very easy. See screenshots ...
LnkShortener is an Android app for shortening URLs. It is using Polr, an open-source URL shortener Getting Started | App Stores | Contribute | Twitter @Lnkshortener | Website Getting Started You can ...
这个目录在Android Studio中通常位于`app/src/main/assets`。 **步骤三:创建SQLiteOpenHelper子类** 在Android中,我们通常通过继承`SQLiteOpenHelper`类来操作数据库。你需要创建一个新的类,覆盖`onCreate()`和`...