- 浏览: 304303 次
- 性别:
- 来自: 广州
最新评论
-
qipa2015:
hao
Android中自定义SeekBar的背景颜色,进度条颜色,以及滑块的图片 -
chungehenyy:
Android中的JSON详细总结 -
wangys198:
请教下怎么加入一个jar包
说说APK反编译(代码插入)的那点事 -
andy199:
Android的TextView使用Html来处理图片显示、字体样式、超链接等 -
tyjxf:
加载图片是个烦人的事,我也正在困扰中
Android实现ListView异步加载图片
[Android]指定浏览器访问指定页面(支持UC、Opera、QQ、Dolphin、Skyfire、Steel、Google)
- 博客分类:
- Android
先看一下系统浏览器com.android.browser 启动类在AndroidManifest.xml 中的声明:
<activity android:theme="@style/BrowserTheme" android:label="@string/application_name" android:name="BrowserActivity" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" android:alwaysRetainTaskState="true" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.speech.action.VOICE_SEARCH_RESULTS" /> <category android:name="android.intent.category.DEFAULT" /> </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="http" /> <data android:scheme="https" /> <data android:scheme="about" /> <data android:scheme="javascript" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" /> <data android:scheme="https" /> <data android:scheme="inline" /> <data android:mimeType="text/html" /> <data android:mimeType="text/plain" /> <data android:mimeType="application/xhtml+xml" /> <data android:mimeType="application/vnd.wap.xhtml+xml" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.WEB_SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="" /> <data android:scheme="http" /> <data android:scheme="https" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEARCH" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> <meta-data android:name="android.app.searchable" android:resource="@xml/searchable" /> </activity>
在action 赋值为”android.intent.action.VIEW“ 时可接收如下scheme 为"http" 等等类型的data 。所以突发奇想,启动该程序后,指定action 及Uri ,即访问指定网页。好了,立马动手实践。代码如下:
package lab.sodino.specifybrowser; import java.util.List; import android.app.Activity; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; /** * @author Sodino * @version 2010年11月8日22时45分47秒 * */ public class VisitUrlAct extends Activity { /** * 值为true时,使用传统方法让用户选择。<br/> * 值为false时,程序自动为用户选定浏览器浏览。<br/> * 目前支持且优先级从高到低为:<br/> * 1.UC浏览器<br/> * 2.Opera浏览器<br/> * 3.QQ浏览器<br/> * 4.Dolphin Browser(不支持WAP)<br/> * 5.Skyfire Browser(不支持WAP)<br/> * 6.Steel Browser(不支持WAP)<br/> * 7.系统浏览器<br/> * 验证是否支持直接启动访问指定页面的方法为:<br/> * 执行下面的<code>doDefault()</code>时会出现如下选择框,<br/> * 选择浏览器,如果能够正常访问,可以指定该浏览器访问指定网页;<br/> * 如果该浏览器启动后没有跳转到指定网页,则不支持。<br/> * 实践中,Go浏览器与天天浏览器并不支持。<br/> * <img src="../../../../choice.png" mce_src="choice.png"/> <br/> * 正确显示图片请在不改变包名的前提下将choice.png放于工程目录下,与src、res同级。<br/> */ private boolean letUserChoice = false; private String visitUrl = "http://blog.csdn.net/sodino"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // showUCBrowser(); // showQQBrowser(); // showOperaBrowser(); // showDolphinBrowser(); // showSkyfireBrowser(); // showSteelBrowser(); if (letUserChoice) { doDefault(); } else { choiceBrowserToVisitUrl(visitUrl); } // 直接退出程序 finish(); } private void choiceBrowserToVisitUrl(String url) { boolean existUC = false, existOpera = false, existQQ = false, existDolphin = false, existSkyfire = false, existSteel = false, existGoogle = false; String ucPath = "", operaPath = "", qqPath = "", dolphinPath = "", skyfirePath = "", steelPath = "", googlePath = ""; PackageManager packageMgr = getPackageManager(); List<PackageInfo> list = packageMgr.getInstalledPackages(0); for (int i = 0; i < list.size(); i++) { PackageInfo info = list.get(i); String temp = info.packageName; if (temp.equals("com.uc.browser")) { // 存在UC ucPath = temp; existUC = true; } else if (temp.equals("com.tencent.mtt")) { // 存在QQ qqPath = temp; existQQ = true; } else if (temp.equals("com.opera.mini.android")) { // 存在Opera operaPath = temp; existOpera = true; } else if (temp.equals("mobi.mgeek.TunnyBrowser")) { dolphinPath = temp; existDolphin = true; } else if (temp.equals("com.skyfire.browser")) { skyfirePath = temp; existSkyfire = true; } else if (temp.equals("com.kolbysoft.steel")) { steelPath = temp; existSteel = true; } else if (temp.equals("com.android.browser")) { // 存在GoogleBroser googlePath = temp; existGoogle = true; } } if (existUC) { gotoUrl(ucPath, url, packageMgr); } else if (existOpera) { gotoUrl(operaPath, url, packageMgr); } else if (existQQ) { gotoUrl(qqPath, url, packageMgr); } else if (existDolphin) { gotoUrl(dolphinPath, url, packageMgr); } else if (existSkyfire) { gotoUrl(skyfirePath, url, packageMgr); } else if (existSteel) { gotoUrl(steelPath, url, packageMgr); } else if (existGoogle) { gotoUrl(googlePath, url, packageMgr); } else { doDefault(); } } private void gotoUrl(String packageName, String url, PackageManager packageMgr) { try { Intent intent; intent = packageMgr.getLaunchIntentForPackage(packageName); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse(url)); startActivity(intent); } catch (Exception e) { // 在1.5及以前版本会要求catch(android.content.pm.PackageManager.NameNotFoundException)异常,该异常在1.5以后版本已取消。 e.printStackTrace(); } } private void doDefault() { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(visitUrl)); startActivity(intent); } /** 直接启动UC,用于验证测试。 */ private void showUCBrowser() { Intent intent = new Intent(); intent.setClassName("com.uc.browser", "com.uc.browser.ActivityUpdate"); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse(visitUrl)); startActivity(intent); } /** 直接启动QQ,用于验证测试。 */ private void showQQBrowser() { Intent intent = new Intent(); intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity"); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse(visitUrl)); startActivity(intent); } /** 直接启动Opera,用于验证测试。 */ private void showOperaBrowser() { Intent intent = new Intent(); intent.setClassName("com.opera.mini.android", "com.opera.mini.android.Browser"); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse(visitUrl)); startActivity(intent); } /** 直接启动Dolphin Browser,用于验证测试。 */ private void showDolphinBrowser() { // 方法一: // Intent intent = new Intent(); // intent.setClassName("mobi.mgeek.TunnyBrowser", // "mobi.mgeek.TunnyBrowser.BrowserActivity"); // intent.setAction(Intent.ACTION_VIEW); // intent.addCategory(Intent.CATEGORY_DEFAULT); // intent.setData(Uri.parse(visitUrl)); // startActivity(intent); // 方法二: gotoUrl("mobi.mgeek.TunnyBrowser", visitUrl, getPackageManager()); } /** 直接启动Skyfire Browser,用于验证测试。 */ private void showSkyfireBrowser() { // 方法一: Intent intent = new Intent(); intent.setClassName("com.skyfire.browser", "com.skyfire.browser.core.Main"); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setData(Uri.parse(visitUrl)); startActivity(intent); // 方法二: // gotoUrl("com.skyfire.browser", visitUrl, getPackageManager()); } /** 直接启动Steel Browser,用于验证测试。 */ private void showSteelBrowser() { // 方法一: // Intent intent = new Intent(); // intent.setClassName("com.kolbysoft.steel", // "com.kolbysoft.steel.Steel"); // intent.setAction(Intent.ACTION_VIEW); // intent.addCategory(Intent.CATEGORY_DEFAULT); // intent.setData(Uri.parse(visitUrl)); // startActivity(intent); // 方法二: gotoUrl("com.kolbysoft.steel", visitUrl, getPackageManager()); } }
[Android]指定浏览器访问指定页面(支持UC、Opera、QQ、Dolphin、Skyfire、Steel、Google) 收藏
先看一下系统浏览器com.android.browser 启动类在AndroidManifest.xml 中的声明:
view plaincopy to clipboardprint?
<activity android:theme="@style/BrowserTheme" android:label="@string/application_name" android:name="BrowserActivity" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" android:alwaysRetainTaskState="true" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
</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="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="inline" />
<data android:mimeType="text/html" />
<data android:mimeType="text/plain" />
<data android:mimeType="application/xhtml+xml" />
<data android:mimeType="application/vnd.wap.xhtml+xml" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
</activity>
<activity android:theme="@style/BrowserTheme" android:label="@string/application_name" android:name="BrowserActivity" android:launchMode="singleTask" android:configChanges="keyboardHidden|orientation" android:alwaysRetainTaskState="true" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.speech.action.VOICE_SEARCH_RESULTS" />
<category android:name="android.intent.category.DEFAULT" />
</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="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="inline" />
<data android:mimeType="text/html" />
<data android:mimeType="text/plain" />
<data android:mimeType="application/xhtml+xml" />
<data android:mimeType="application/vnd.wap.xhtml+xml" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable" android:resource="@xml/searchable" />
</activity>
在action 赋值为”android.intent.action.VIEW“ 时可接收如下scheme 为"http" 等等类型的data 。所以突发奇想,启动该程序后,指定action 及Uri ,即访问指定网页。好了,立马动手实践。代码如下:
view plaincopy to clipboardprint?
package lab.sodino.specifybrowser;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
/**
* @author Sodino
* @version 2010年11月8日22时45分47秒
* */
public class VisitUrlAct extends Activity {
/**
* 值为true时,使用传统方法让用户选择。<br/>
* 值为false时,程序自动为用户选定浏览器浏览。<br/>
* 目前支持且优先级从高到低为:<br/>
* 1.UC浏览器<br/>
* 2.Opera浏览器<br/>
* 3.QQ浏览器<br/>
* 4.Dolphin Browser(不支持WAP)<br/>
* 5.Skyfire Browser(不支持WAP)<br/>
* 6.Steel Browser(不支持WAP)<br/>
* 7.系统浏览器<br/>
* 验证是否支持直接启动访问指定页面的方法为:<br/>
* 执行下面的<code>doDefault()</code>时会出现如下选择框,<br/>
* 选择浏览器,如果能够正常访问,可以指定该浏览器访问指定网页;<br/>
* 如果该浏览器启动后没有跳转到指定网页,则不支持。<br/>
* 实践中,Go浏览器与天天浏览器并不支持。<br/>
* <img src="../../../../choice.png" mce_src="choice.png"/> <br/>
* 正确显示图片请在不改变包名的前提下将choice.png放于工程目录下,与src、res同级。<br/>
*/
private boolean letUserChoice = false;
private String visitUrl = "http://blog.csdn.net/sodino";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// showUCBrowser();
// showQQBrowser();
// showOperaBrowser();
// showDolphinBrowser();
// showSkyfireBrowser();
// showSteelBrowser();
if (letUserChoice) {
doDefault();
} else {
choiceBrowserToVisitUrl(visitUrl);
}
// 直接退出程序
finish();
}
private void choiceBrowserToVisitUrl(String url) {
boolean existUC = false, existOpera = false, existQQ = false, existDolphin = false, existSkyfire = false, existSteel = false, existGoogle = false;
String ucPath = "", operaPath = "", qqPath = "", dolphinPath = "", skyfirePath = "", steelPath = "", googlePath = "";
PackageManager packageMgr = getPackageManager();
List<PackageInfo> list = packageMgr.getInstalledPackages(0);
for (int i = 0; i < list.size(); i++) {
PackageInfo info = list.get(i);
String temp = info.packageName;
if (temp.equals("com.uc.browser")) {
// 存在UC
ucPath = temp;
existUC = true;
} else if (temp.equals("com.tencent.mtt")) {
// 存在QQ
qqPath = temp;
existQQ = true;
} else if (temp.equals("com.opera.mini.android")) {
// 存在Opera
operaPath = temp;
existOpera = true;
} else if (temp.equals("mobi.mgeek.TunnyBrowser")) {
dolphinPath = temp;
existDolphin = true;
} else if (temp.equals("com.skyfire.browser")) {
skyfirePath = temp;
existSkyfire = true;
} else if (temp.equals("com.kolbysoft.steel")) {
steelPath = temp;
existSteel = true;
} else if (temp.equals("com.android.browser")) {
// 存在GoogleBroser
googlePath = temp;
existGoogle = true;
}
}
if (existUC) {
gotoUrl(ucPath, url, packageMgr);
} else if (existOpera) {
gotoUrl(operaPath, url, packageMgr);
} else if (existQQ) {
gotoUrl(qqPath, url, packageMgr);
} else if (existDolphin) {
gotoUrl(dolphinPath, url, packageMgr);
} else if (existSkyfire) {
gotoUrl(skyfirePath, url, packageMgr);
} else if (existSteel) {
gotoUrl(steelPath, url, packageMgr);
} else if (existGoogle) {
gotoUrl(googlePath, url, packageMgr);
} else {
doDefault();
}
}
private void gotoUrl(String packageName, String url,
PackageManager packageMgr) {
try {
Intent intent;
intent = packageMgr.getLaunchIntentForPackage(packageName);
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(url));
startActivity(intent);
} catch (Exception e) {
// 在1.5及以前版本会要求catch(android.content.pm.PackageManager.NameNotFoundException)异常,该异常在1.5以后版本已取消。
e.printStackTrace();
}
}
private void doDefault() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动UC,用于验证测试。 */
private void showUCBrowser() {
Intent intent = new Intent();
intent.setClassName("com.uc.browser", "com.uc.browser.ActivityUpdate");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动QQ,用于验证测试。 */
private void showQQBrowser() {
Intent intent = new Intent();
intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动Opera,用于验证测试。 */
private void showOperaBrowser() {
Intent intent = new Intent();
intent.setClassName("com.opera.mini.android",
"com.opera.mini.android.Browser");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动Dolphin Browser,用于验证测试。 */
private void showDolphinBrowser() {
// 方法一:
// Intent intent = new Intent();
// intent.setClassName("mobi.mgeek.TunnyBrowser",
// "mobi.mgeek.TunnyBrowser.BrowserActivity");
// intent.setAction(Intent.ACTION_VIEW);
// intent.addCategory(Intent.CATEGORY_DEFAULT);
// intent.setData(Uri.parse(visitUrl));
// startActivity(intent);
// 方法二:
gotoUrl("mobi.mgeek.TunnyBrowser", visitUrl, getPackageManager());
}
/** 直接启动Skyfire Browser,用于验证测试。 */
private void showSkyfireBrowser() {
// 方法一:
Intent intent = new Intent();
intent.setClassName("com.skyfire.browser",
"com.skyfire.browser.core.Main");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
// 方法二:
// gotoUrl("com.skyfire.browser", visitUrl, getPackageManager());
}
/** 直接启动Steel Browser,用于验证测试。 */
private void showSteelBrowser() {
// 方法一:
// Intent intent = new Intent();
// intent.setClassName("com.kolbysoft.steel",
// "com.kolbysoft.steel.Steel");
// intent.setAction(Intent.ACTION_VIEW);
// intent.addCategory(Intent.CATEGORY_DEFAULT);
// intent.setData(Uri.parse(visitUrl));
// startActivity(intent);
// 方法二:
gotoUrl("com.kolbysoft.steel", visitUrl, getPackageManager());
}
}
package lab.sodino.specifybrowser;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
/**
* @author Sodino
* @version 2010年11月8日22时45分47秒
* */
public class VisitUrlAct extends Activity {
/**
* 值为true时,使用传统方法让用户选择。<br/>
* 值为false时,程序自动为用户选定浏览器浏览。<br/>
* 目前支持且优先级从高到低为:<br/>
* 1.UC浏览器<br/>
* 2.Opera浏览器<br/>
* 3.QQ浏览器<br/>
* 4.Dolphin Browser(不支持WAP)<br/>
* 5.Skyfire Browser(不支持WAP)<br/>
* 6.Steel Browser(不支持WAP)<br/>
* 7.系统浏览器<br/>
* 验证是否支持直接启动访问指定页面的方法为:<br/>
* 执行下面的<code>doDefault()</code>时会出现如下选择框,<br/>
* 选择浏览器,如果能够正常访问,可以指定该浏览器访问指定网页;<br/>
* 如果该浏览器启动后没有跳转到指定网页,则不支持。<br/>
* 实践中,Go浏览器与天天浏览器并不支持。<br/>
* <img src="../../../../choice.png" mce_src="choice.png"/> <br/>
* 正确显示图片请在不改变包名的前提下将choice.png放于工程目录下,与src、res同级。<br/>
*/
private boolean letUserChoice = false;
private String visitUrl = "http://blog.csdn.net/sodino";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// showUCBrowser();
// showQQBrowser();
// showOperaBrowser();
// showDolphinBrowser();
// showSkyfireBrowser();
// showSteelBrowser();
if (letUserChoice) {
doDefault();
} else {
choiceBrowserToVisitUrl(visitUrl);
}
// 直接退出程序
finish();
}
private void choiceBrowserToVisitUrl(String url) {
boolean existUC = false, existOpera = false, existQQ = false, existDolphin = false, existSkyfire = false, existSteel = false, existGoogle = false;
String ucPath = "", operaPath = "", qqPath = "", dolphinPath = "", skyfirePath = "", steelPath = "", googlePath = "";
PackageManager packageMgr = getPackageManager();
List<PackageInfo> list = packageMgr.getInstalledPackages(0);
for (int i = 0; i < list.size(); i++) {
PackageInfo info = list.get(i);
String temp = info.packageName;
if (temp.equals("com.uc.browser")) {
// 存在UC
ucPath = temp;
existUC = true;
} else if (temp.equals("com.tencent.mtt")) {
// 存在QQ
qqPath = temp;
existQQ = true;
} else if (temp.equals("com.opera.mini.android")) {
// 存在Opera
operaPath = temp;
existOpera = true;
} else if (temp.equals("mobi.mgeek.TunnyBrowser")) {
dolphinPath = temp;
existDolphin = true;
} else if (temp.equals("com.skyfire.browser")) {
skyfirePath = temp;
existSkyfire = true;
} else if (temp.equals("com.kolbysoft.steel")) {
steelPath = temp;
existSteel = true;
} else if (temp.equals("com.android.browser")) {
// 存在GoogleBroser
googlePath = temp;
existGoogle = true;
}
}
if (existUC) {
gotoUrl(ucPath, url, packageMgr);
} else if (existOpera) {
gotoUrl(operaPath, url, packageMgr);
} else if (existQQ) {
gotoUrl(qqPath, url, packageMgr);
} else if (existDolphin) {
gotoUrl(dolphinPath, url, packageMgr);
} else if (existSkyfire) {
gotoUrl(skyfirePath, url, packageMgr);
} else if (existSteel) {
gotoUrl(steelPath, url, packageMgr);
} else if (existGoogle) {
gotoUrl(googlePath, url, packageMgr);
} else {
doDefault();
}
}
private void gotoUrl(String packageName, String url,
PackageManager packageMgr) {
try {
Intent intent;
intent = packageMgr.getLaunchIntentForPackage(packageName);
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(url));
startActivity(intent);
} catch (Exception e) {
// 在1.5及以前版本会要求catch(android.content.pm.PackageManager.NameNotFoundException)异常,该异常在1.5以后版本已取消。
e.printStackTrace();
}
}
private void doDefault() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动UC,用于验证测试。 */
private void showUCBrowser() {
Intent intent = new Intent();
intent.setClassName("com.uc.browser", "com.uc.browser.ActivityUpdate");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动QQ,用于验证测试。 */
private void showQQBrowser() {
Intent intent = new Intent();
intent.setClassName("com.tencent.mtt", "com.tencent.mtt.MainActivity");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动Opera,用于验证测试。 */
private void showOperaBrowser() {
Intent intent = new Intent();
intent.setClassName("com.opera.mini.android",
"com.opera.mini.android.Browser");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
}
/** 直接启动Dolphin Browser,用于验证测试。 */
private void showDolphinBrowser() {
// 方法一:
// Intent intent = new Intent();
// intent.setClassName("mobi.mgeek.TunnyBrowser",
// "mobi.mgeek.TunnyBrowser.BrowserActivity");
// intent.setAction(Intent.ACTION_VIEW);
// intent.addCategory(Intent.CATEGORY_DEFAULT);
// intent.setData(Uri.parse(visitUrl));
// startActivity(intent);
// 方法二:
gotoUrl("mobi.mgeek.TunnyBrowser", visitUrl, getPackageManager());
}
/** 直接启动Skyfire Browser,用于验证测试。 */
private void showSkyfireBrowser() {
// 方法一:
Intent intent = new Intent();
intent.setClassName("com.skyfire.browser",
"com.skyfire.browser.core.Main");
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse(visitUrl));
startActivity(intent);
// 方法二:
// gotoUrl("com.skyfire.browser", visitUrl, getPackageManager());
}
/** 直接启动Steel Browser,用于验证测试。 */
private void showSteelBrowser() {
// 方法一:
// Intent intent = new Intent();
// intent.setClassName("com.kolbysoft.steel",
// "com.kolbysoft.steel.Steel");
// intent.setAction(Intent.ACTION_VIEW);
// intent.addCategory(Intent.CATEGORY_DEFAULT);
// intent.setData(Uri.parse(visitUrl));
// startActivity(intent);
// 方法二:
gotoUrl("com.kolbysoft.steel", visitUrl, getPackageManager());
}
}
ok,成功了。
附choice.png图片:
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sodino/archive/2010/11/08/5996490.aspx
发表评论
-
Android 学习资料大集合
2012-02-22 11:23 2560<script type="t ... -
总结了近百个Android优秀开源项目,覆盖Android开发的每个
2012-02-21 11:21 1967Android开发又将带来新一轮热潮,很多开发者都投入到这 ... -
说说APK反编译(代码插入)的那点事
2012-02-21 09:54 9089很多人热衷于逆向工程,其过程中既可以学习作者的思路,又可以锻炼 ... -
(转)一种新的MAT使用方法分析内存溢出问题
2012-02-21 09:42 1996相信很多人都用过MAT来分析内存溢出,而且网上有很多的使用方法 ... -
(转)Android* 应用性能调试
2012-02-08 09:33 1520概述 创造愉快用户体验的关键是开发响应快捷的应用。借助And ... -
Android SDK 中Android.net.wi
2012-02-06 15:20 1861这里列了很多,但是大致可以分为四个主要的类ScanResult ... -
android 从assets和res中读取文件(转)
2012-02-03 15:02 25471. 相关文件夹介绍 ... -
textview 超链接去掉下划线和设置超链接颜色
2011-12-06 17:15 3806/** * 点击超链接时打开其他博主资料页面 * ... -
按钮Listview等点击效果
2011-11-12 22:58 4020想设置listview中每行在点击、选中等不同状态下有不同的背 ... -
android 获取视频和图片的缩略图
2011-11-12 01:53 118291 在显示视频图片列表时,发送彩信时,制作幻灯片时都需要显示视 ... -
调用android系统图标
2011-10-31 16:54 2854Android系统中自带了很多图标,我们的程序可以方便使用。 ... -
The content of the adapter has changed but ListView did not receive a notificati
2011-10-27 15:43 1172在Android开发过程中,使用了大量的ListView,发现 ... -
android的上下文菜单---context menu
2011-09-23 09:53 1270android的菜单有三种: ... -
选择系统图片方法时返回图片真实路径
2011-09-21 10:36 1627protected void onActivityResul ... -
android一些技巧
2011-09-01 18:08 1511EditText ed = ... -
android TextView中超链接的事件捕捉(textview上LINK的点击事件)
2011-08-19 18:43 2534package com.cm; import java. ... -
Android的TextView使用Html来处理图片显示、字体样式、超链接等
2011-08-19 18:38 4584转载:http://my.oschina.net/java ... -
Android 设置EditText显示或隐藏密码
2011-08-17 16:37 2241设置EditText显示或隐藏密码. 在CheckBox的o ... -
android调用系统资源裁剪图片
2011-08-08 12:52 28501 import java.io.File; 2 import ... -
Android 复制 粘贴
2011-07-25 10:18 2534Android 复制 粘贴 ClipboardManager ...
相关推荐
Android Studio Dolphin (2021.3.1) Canary 3 (android-studio-2021.3.1.3-mac.zip)海豚 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.3.1.3-mac...
Android Studio Dolphin (2021.3.1) Canary 4 (android-studio-2021.3.1.4-windows.zip)海豚 适用于Windows x86_64系统: Android Studio版本排序: Dolphin | 2021.3.1 Chipmunk | 2021.2.1 Bumblebee | 2021.1.1...
Android Studio Dolphin (2021.3.1) Canary 2 (android-studio-2021.3.1.2-mac.zip)海豚 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.3.1.2-mac...
Android Studio Dolphin (2021.3.1) Beta 1(android-studio-2021.3.1.10-mac.zip)海豚 适用于macOS x86_64系统。 Android Studio版本排序: Electric Eel | 2022.1.1 Dolphin | 2021.3.1 Chipmunk | 2021.2.1 ...
Android Studio Dolphin (2021.3.1) Beta 1 (android-studio-2021.3.1.10-mac_arm.zip)海豚 适用于macOS Arm系统。 Android Studio版本排序: Electric Eel | 2022.1.1 Dolphin | 2021.3.1 Chipmunk | 2021.2.1 ...
Android Studio Dolphin (2021.3.1) Canary 2 (android-studio-2021.3.1.2-windows.zip)海豚 适用于Windows系统: Android Studio版本排序: Dolphin | 2021.3.1 Chipmunk | 2021.2.1 Bumblebee | 2021.1.1 Arctic...
Android Studio Dolphin (2021.3.1) Canary 4 (android-studio-2021.3.1.4-mac_arm.zip)海豚 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载解压使用: Android Studio Dolphin (android-studio-...
Android Studio Dolphin (2021.3.1) Canary 4 (android-studio-2021.3.1.4-mac_arm.zip)海豚 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载解压使用: Android Studio Dolphin (android-studio-...
Android Studio Dolphin (2021.3.1) Canary 7 (android-studio-2021.3.1.7-windows.zip)海豚 适用于Windows x86_64系统。 Android Studio版本排序: Dolphin | 2021.3.1 Chipmunk | 2021.2.1 Bumblebee | 2021.1.1...
Android Studio Dolphin (2021.3.1) Canary 2 (android-studio-2021.3.1.2-mac_arm.zip)海豚 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.3.1.2-...
Android Studio Dolphin (2021.3.1) Canary 4 (android-studio-2021.3.1.4-mac.zip)海豚 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: Android Studio Dolphin ...
Android Studio Dolphin (2021.3.1) Canary 3 (android-studio-2021.3.1.3-mac_arm.zip)海豚 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.3.1.3-...
Android Studio Dolphin (2021.3.1) Canary 3 (android-studio-2021.3.1.3-windows.zip)海豚 适用于Windows x86_64系统: Android Studio版本排序: Dolphin | 2021.3.1 Chipmunk | 2021.2.1 Bumblebee | 2021.1....
Android Studio Dolphin (2021.3.1) Canary 4 (android-studio-2021.3.1.4-mac.zip)海豚 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: Android Studio Dolphin ...
Android Studio Dolphin 2021.3.1(android-studio-2021.3.1.10-linux.tar.gz)适用于Linux(64-bit)系统: Android Studio版本排序: Electric Eel | 2022.1.1 Dolphin | 2021.3.1 Chipmunk | 2021.2.1 Bumblebee |...
Android Studio Dolphin (2021.3.1) Beta 1 (android-studio-2021.3.1.10-windows.zip)海豚 适用于Windows x86_64系统。 Android Studio版本排序: Electric Eel | 2022.1.1 Dolphin | 2021.3.1 Chipmunk | 2021.2...
Android Studio Dolphin (2021.3.1) Canary 3 (android-studio-2021.3.1.3-mac_arm.zip)海豚 适用于macOS Arm芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: android-studio-2021.3.1.3-...
Android Studio Dolphin 2021.3.1 Patch 1 Windows IDE 安装版 (64-bit)
android-studio-2021.3.1.15-windows 代号“海豚”(Dolphin)
Apache DolphinScheduler(apache-dolphinscheduler-3.0.0-beta-1-bin.tar....DolphinScheduler以DAG流式的方式将Task组装起来,可实时监控任务的运行状态,同时支持重试、从指定节点恢复失败、暂停及Kill任务等操作。