html打开androidapp
㈠ 安卓开发怎么在APP内部调用手机系统浏览器打开指定html并获取HTML的数据
Android开发_如何调用 浏览器访问网页和Html文件
一、启动android默认浏览器
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('http://www.cnblogs.com');
intent.setData(content_url);
startActivity(intent);
这样子,android就可以调用起手机默认的浏览器访问。
二、指定相应的浏览器访问
1、指定android自带的浏览器访问
( “com.android.browser”:packagename ;“com.android.browser.BrowserActivity”:启动主activity)
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('http://www.cnblogs.com');
intent.setData(content_url);
intent.setClassName('com.android.browser','com.android.browser.BrowserActivity');
startActivity(intent);
2、启动其他浏览器(当然该浏览器必须安装在机器上)
只要修改以下相应的packagename 和 主启动activity即可调用其他浏览器
intent.setClassName('com.android.browser','com.android.browser.BrowserActivity');
uc浏览器':'com.uc.browser', 'com.uc.browser.ActivityUpdate“
opera :'com.opera.mini.android', 'com.opera.mini.android.Browser'
qq浏览器:'com.tencent.mtt', 'com.tencent.mtt.MainActivity'
三、打开本地html文件
打开本地的html文件的时候,一定要指定某个浏览器,而不能采用方式一来浏览,具体示例代码如下
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('content://com.android.htmlfileprovider/sdcard/help.html');
intent.setData(content_url);
intent.setClassName('com.android.browser','com.android.browser.BrowserActivity');
startActivity(intent);
关键点是调用了”content“这个filter。
以前有在win32编程的朋友,可能会觉得用这种形式”file://sccard/help.html“是否可以,可以很肯定的跟你说,默认的浏览器设置是没有对”file“这个进行解析的,如果要让你的默认android浏览器有这个功能需要自己到android源码修改manifest.xml文件,然后自己编译浏览器代码生成相应的apk包来重新在机器上安装。
大体的步骤如下:
1、打开 packages/apps/Browser/AndroidManifest.xml文件把加到相应的后面就可以了
2、重新编译打包,安装,这样子,新的浏览器就支持”file“这个形式了
有兴趣的可以去试试。
㈡ 怎样 用html5开发android app
下载安装MyEclipse2014,Android SDK,eclipse(需配置Android开发环境)
Java和Android环境安装与配置,将另写经验分享,读者也可网络参考其他相关资料,自行安装
打开MyEclipse2014,新建一个HTML5 Mobile Application Project,命名,例如:hello
html5程序在工程www目录下编辑;
编辑好我们的html5程序,下面就要开始学习打包了
这里介绍两种打包方式:1、PhoneGap Build Service 打包
PhoneGap官网有相关教程可参考,不具体介绍
2、android SDK +eclispe 打包
android SDK +eclispe 打包(前提已配置好,android开发环境):
Step1、启动eclipse,新建Android Application Project,即Android工程,命名,例如:hello
Step2、将前面Myeclipse2014中编辑好的HTML5程序(www整个目录)拷至刚刚在eclipse新建hello工程对应assets目录下面
Step3、下面要做的就是如何将我们的HTML5程序在Android应用中启动,这里我们要使用Android系统自带的WebView控件(具体信息参考Adroid开发文档)---在工程下找到res->layout->activity_main.xml并打开,向里面插入WebView控件,编辑好自己想要的样式
Step4、在主程序入口,用刚刚编辑好的WebView控件将HTML5程序引入,此时,主体功能已实现,编译工程即可得到apk
㈢ 怎么用网页的超级链接调用安卓手机的app
一、通过html页面打开Android本地的app
1、首先在编写一个简单的html页面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="m://my.com/">打开app</a><br/>
</body>
</html>
2、在Android本地app的配置
在AndroidManifest的清单文件里的intent-filte中加入如下元素:
<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:host="my.com"
android:scheme="m" />
</intent-filter>
示例截图如下:
然后使用“手机浏览器”或者“webview”的方式打开这个本地的html网页,点击“打开APP”即可成功开启本地的指定的app
二、如何通过这个方法获取网页带过来的数据
只能打开就没什么意思了,最重要的是,我们要传递数据,那么怎么去传递数据呢?
我们可以使用上述的方法,把一些数据传给本地app,那么首先我们更改一下网页,代码修改后:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="m://my.com/?arg0=0&arg1=1">打开app</a><br/>
</body>
</html>
(1).假如你是通过浏览器打开这个网页的,那么获取数据的方式为:
Uri uri = getIntent().getData(); String test1= uri.getQueryParameter("arg0"); String test2= uri.getQueryParameter("arg1");
(2)如果使用webview访问该网页,获取数据的操作为:
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri=Uri.parse(url);
if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){
String arg0=uri.getQueryParameter("arg0");
String arg1=uri.getQueryParameter("arg1");
}else{
view.loadUrl(url);
}
return true;
}
});