當前位置:首頁 » 安卓系統 » html打開androidapp

html打開androidapp

發布時間: 2023-03-25 22:50:50

㈠ 安卓開發怎麼在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;
}
});

熱點內容
javawebeclipse編譯 發布:2025-05-14 11:35:24 瀏覽:935
可編程式控制制器試題 發布:2025-05-14 11:25:32 瀏覽:119
dsp混合編程 發布:2025-05-14 11:23:10 瀏覽:248
mysql添加存儲過程 發布:2025-05-14 11:23:01 瀏覽:879
房車旅遊自媒體有腳本嗎 發布:2025-05-14 11:18:18 瀏覽:125
android輸入法鍵盤 發布:2025-05-14 11:15:48 瀏覽:658
谷歌商店安卓手機在哪裡 發布:2025-05-14 11:13:46 瀏覽:535
編程貓銷售女 發布:2025-05-14 11:13:36 瀏覽:335
安卓卡無翼怎麼出小黑屋 發布:2025-05-14 11:13:00 瀏覽:581
買商用筆記本電腦主要看哪些配置 發布:2025-05-14 11:12:15 瀏覽:950