當前位置:首頁 » 安卓系統 » androidintent瀏覽器

androidintent瀏覽器

發布時間: 2023-08-21 05:51:44

A. Android 從瀏覽器鏈接打開App

需求很簡單,通過Html頁面中的一個超鏈接打開我們的App,實現也很簡單。
網頁:

scheme:代表Scheme的協議名稱(必要族模)

host和path可選擇添加

query:代表URL傳遞的數據
簡單的寫一個頁面:

接卸來開始配置AndroidManifest.xml文件,在有 <action android:name="android.intent.action.MAIN" /> 的actvity配置下新增一個filter,注意是新增一個filter,例如:

這里注意scheme里參數和我們在html頁面猜卜里的對應關系,不要弄錯,多了,我們在a標簽里還傳遞了參數,接受也很穗穗穗簡單,例如:

寫完,我們來看看效果:

成功實現,控制台的日誌也能看到我們的參數確實傳遞過來了:

就這樣,記錄下來,收工。

B. 如何在Android中調用瀏覽器打開網頁

android打開系統默認的軟體,通常使用的是inent意圖這個類,如下打開瀏覽器: Intent
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// get the view web intent
Intent intent = this.getViewWebIntent();
this.(intent);
// set the className to use the specific browser to open the webpage.
intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");
startActivity(intent);
}

/*
*get the desired view web intent
*/
private Intent getViewWebIntent() {
Intent viewWebIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.2cto.com");
viewWebIntent.setData(uri);
return viewWebIntent;
}
裡面可以填上任意的url,也可以利用inent發送信息、撥打電話,記日歷

C. Android開發之Intent.Action Android中Intent的各種常見作用【轉】

1 Intent.ACTION_MAIN

String: Android.intent.action.MAIN標識Activity為一個程序的開始。比較常用。Input:nothingOutput:nothing

2 Intent.Action_CALL

【直接呼叫,在6.0之後的版本需要獲取許可權,詳見 Android開發學習之路-Android6.0運行時許可權【轉】 】

Stirng: android.intent.action.CALL呼叫指定的電話號碼。Input:電話號碼。數據格式為:tel:+phone number Output:Nothing

Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL);

intent.setData(Uri.parse("tel:1320010001");

startActivity(intent);

3 Intent.Action.DIAL

String: action.intent.action.DIAL調用撥號面板

Intent intent=new Intent();intent.setAction(Intent.ACTION_DIAL);  //android.intent.action.DIAL

intent.setData(Uri.parse("tel:1320010001");

startActivity(intent);

Input:電話號碼。數據格式為:tel:+phone number Output:Nothing說明:打開Android的撥號UI。如果沒有設置數據,則打開一個空的UI,如果設置數據,action.DIAL則通過調用getData()獲取電話號碼。但設置電話號碼的數據格式為 tel:+phone number.

4 Intent.Action.ALL_APPS

String: andriod.intent.action.ALL_APPS列出所有的應用。Input:Nothing.Output:Nothing.

5Intent.ACTION_ANSWER

Stirng:android.intent.action.ANSWER處理呼入的電話。Input:Nothing.Output:Nothing.

6 Intent.ACTION_ATTACH_DATA

String: android.action.ATTCH_DATA別用於指定一些數據應該附屬於一些其他的地方,例如,圖片數據應該附屬於聯系人Input: DataOutput:nothing

7 Intent.ACTION_BUG_REPORT

String: android.intent.action.BUG_REPORT顯示Dug報告。Input:nothingoutput:nothing

8 Intent.Action_CALL_BUTTON

String: android.action.intent.CALL_BUTTON.相當於用戶按下「撥號」鍵。經測試顯示的是「通話記錄」Input:nothingOutput:nothing

Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);startActivity(intent);

9 Intent.ACTION_CHOOSER

String: android.intent.action.CHOOSER顯示一個activity選擇器,允許用戶在進程之前選擇他們想要的,與之對應的是Intent.ACTION_GET_CONTENT.

10. Intent.ACTION_GET_CONTENT

String: android.intent.action.GET_CONTENT允許用戶選擇特殊種類的數據,並返回(特殊種類的數據:照一張相片或錄一段音)

Input: TypeOutput:URI

int requestCode = 1001;Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"

intent.setType("image/*"); // 查看類型,如果是其他類型,比如視頻則替換成 video/*,或 */*

Intent wrapperIntent = Intent.createChooser(intent, null);startActivityForResult(wrapperIntent, requestCode);

11 Intent.ACTION_VIEW

String:android.intent.action.VIEW用於顯示用戶的數據。比較通用,會根據用戶的數據類型打開相應的Activity。比如 tel:13400010001打開撥號程序,http://www.g.cn則會打開瀏覽器等。

Uri uri = Uri.parse("http://www.google.com"); //瀏覽器 Uri uri =Uri.parse("tel:1232333"); //撥號程序

Uri uri=Uri.parse("geo:39.899533,116.036476"); //打開地圖定位

Intent it = new Intent(Intent.ACTION_VIEW,uri);

startActivity(it);

//播放視頻

Intent intent = new Intent(Intent.ACTION_VIEW);

Uri uri = Uri.parse("file:///sdcard/media.mp4");

intent.setDataAndType(uri, "video/*");

startActivity(intent);

//調用發送簡訊的程序

Intent it = new Intent(Intent.ACTION_VIEW);

it.putExtra("sms_body", "信息內容...");

it.setType("vnd.android-dirs-sms");

startActivity(it);

12 Intent.ACTION_SENDTO

String: android.intent.action.SENDTO

說明:發送簡訊息

//發送簡訊息 Uri uri = Uri.parse("smsto:13200100001");

Intent it = new Intent(Intent.ACTION_SENDTO, uri);

it.putExtra("sms_body", "信息內容...");

startActivity(it);

//發送彩信,設備會提示選擇合適的程序發送 Uri uri = Uri.parse("content://media/external/images/media/23");

//設備中的資源(圖像或其他資源)

Intent intent = new Intent(Intent.ACTION_SEND);

intent.putExtra("sms_body", "內容");

intent.putExtra(Intent.EXTRA_STREAM, uri);

intent.setType("image/png");

startActivity(it);

//Email Intent intent=new Intent(Intent.ACTION_SEND);

String[] tos={"[email protected]"};

String[] ccs={"[email protected]"};

intent.putExtra(Intent.EXTRA_EMAIL, tos);

intent.putExtra(Intent.EXTRA_CC, ccs);

intent.putExtra(Intent.EXTRA_TEXT, "The email body text");

intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");

intent.setType("message/rfc822");

startActivity(Intent.createChooser(intent, "Choose Email Client"));

13 Intent.ACTION_GET_CONTENT

//選擇圖片 requestCode 返回的標識

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"

intent.setType(contentType); //查看類型 String IMAGE_UNSPECIFIED = "image/*";

Intent wrapperIntent = Intent.createChooser(intent, null);

((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//添加音頻

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";

Intent wrapperIntent = Intent.createChooser(intent, null);

((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//拍攝視頻

int rationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.ration", 60);

Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);

intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, rationLimit);

startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);

//視頻

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";

Intent wrapperIntent = Intent.createChooser(intent, null);

((Activity) context).startActivityForResult(wrapperIntent, requestCode);

//錄音

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audior";

intent.setClassName("com.android.soundrecorder",

"com.android.soundrecorder.SoundRecorder");

((Activity) context).startActivityForResult(intent, requestCode);

//拍照 REQUEST_CODE_TAKE_PICTURE 為返回的標識

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";

intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content:/s/scrapSpace");

startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);

D. 安卓開發怎麼在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「這個形式了
有興趣的可以去試試。

E. Android從瀏覽器中打開本地應用

開發中遇到的一些問題特此記錄:

1、應用場景一  在瀏覽器中要求直接打開到安裝的應用中  

需要在該應用的啟動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:host="com..test"

       android:scheme="text"/>

</Intent-filter>

此處對應的data數據 跟伺服器人員進行交互的時候為:text://com..test

2、中前應用場景二 在瀏覽器中進行打開 並且要求打開指定的具體的頁面

首先得在清單文件中進行上面一樣的配置  接著和從其他跳轉的activity中獲取的一樣 ,通過intent來進行數據的獲取

if(intent !=null) {

     Uri uri = intent.getData();

      if(uri !=null) {

           String host = uri.getHost();

     帆扒       LogUtil.d(TAG,host);

             String data = uri.getQueryParameter("code");

           try{

                  jumpData= URLDecoder.decode(data,"UTF-8");

                  LogUtil.d(TAG,jumpData);

            }catch(UnsupportedEncodingException e) {

                  e.printStackTrace();

         賣轎清   }

      }

}

這樣獲取到的數據就是需要的數據 所要跳轉的具體信息具體跳轉類型都會獲取到,然後在跟以前一樣進行跳轉就可以了。

F. Android 調用手機瀏覽器的正確方式

intent-filter詳解

前提: 本人通過手機默認瀏覽器及html查看器都可以成功調起本地app

調起App時,獲取到html中的內容如下,該內容被封裝到Intent中,並通過 intent.getData()獲取(使用Uri表示),我們通過uri.getQueryParameter()獲取具體欄位的值。

1.當App已啟動時,也可以調起app,只是獲取不到Intent中的數據。我的大概理解是Android中Activity啟動時通過Intent在傳遞數據,如果我們的Activity已經啟動,沒有再次獲取Intent對象,android:launchMode="singleInstance";這個需要其它同學解答下。
2.為什麼我把Activity啟動模式設置為android:launchMode="singleInstance"?因為如果我們使用默認的standard模式,會發現被調起的app的Activity運行在瀏覽器的任務棧中了。這是Activity啟動模式對調起App的影響。
3.有什麼不足之處,希望大家指正。謝謝

G. android開發怎麼調用瀏覽器打開一個鏈接

在安卓代碼中調用瀏覽器來打開相應的網頁,一般有以下幾種方式

  1. 調用默認瀏覽器。

  2. 其他瀏覽器。

  3. 自定義一個簡單的WebView瀏覽器。

【原理】

主要是通過代碼進行調用已有或者未有的瀏覽器進行打開相應的網頁進行瀏覽。

【詳細實現步奏】

一.調用默認瀏覽器

優缺點:部分手機可能連默認的瀏覽器都沒有。


java">Intentintent=newIntent();
//Intentintent=newIntent(Intent.ACTION_VIEW,uri);
intent.setAction("android.intent.action.VIEW");
Uricontent_url=Uri.parse("此處填鏈接");
intent.setData(content_url);
startActivity(intent);

二.其他瀏覽器,制定打開

缺點:必須知道打開的瀏覽器的包名,大部分用戶可能沒有安裝這些瀏覽器

Intentintent=newIntent();
intent.setAction("android.intent.action.VIEW");
Uricontent_url=Uri.parse("此處填鏈接");
intent.setData(content_url);
intent.setClassName("瀏覽器包名","瀏覽器首頁");
startActivity(intent);


三.自定義一個簡單的WebView瀏覽器

優缺點:推薦使用,不必擔心手機上是否有瀏覽器。

mWebView=(WebView)findViewById(R.id.baseweb_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(newWebViewClient());
WebViewmyWebView=(WebView)findViewById(R.id.webview);
myWebView.loadUrl("xxx.com");

【最後】

每種方法根據個人需要進行選用,沒其他特別因素推薦使用第三種方案。

熱點內容
滑板鞋腳本視頻 發布:2025-02-02 09:48:54 瀏覽:432
群暉怎麼玩安卓模擬器 發布:2025-02-02 09:45:23 瀏覽:557
三星安卓12彩蛋怎麼玩 發布:2025-02-02 09:44:39 瀏覽:743
電腦顯示連接伺服器錯誤 發布:2025-02-02 09:24:10 瀏覽:537
瑞芯微開發板編譯 發布:2025-02-02 09:22:54 瀏覽:146
linux虛擬機用gcc編譯時顯示錯誤 發布:2025-02-02 09:14:01 瀏覽:235
java駝峰 發布:2025-02-02 09:13:26 瀏覽:651
魔獸腳本怎麼用 發布:2025-02-02 09:10:28 瀏覽:538
linuxadobe 發布:2025-02-02 09:09:43 瀏覽:212
sql2000資料庫連接 發布:2025-02-02 09:09:43 瀏覽:726