欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

html5添加到安卓桌面图标,Android向桌面添加快捷方式,使其指向特定的网页

发布时间:2025/3/20 94 豆豆
生活随笔 收集整理的这篇文章主要介绍了 html5添加到安卓桌面图标,Android向桌面添加快捷方式,使其指向特定的网页 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

转载:

http://www.cnblogs.com/wanyao/archive/2011/11/27/2265333.html

今天遇到一个需求,就是向桌面添加一个快捷方式,使点击时链接到特定的网页。网上找了一下,看到这篇文章

http://www.moandroid.com/?p=1699

受其启发,实现了该功能。

/*

* 在桌面添加快捷方式

* @param icon 快捷方式图标

* @param name 快捷方式名称

* @param uri 快捷方式的intent Uri

*/

public void addShortcut(Parcelable icon, String name, Uri uri){

Intent intentAddShortcut = new Intent(ACTION_ADD_SHORTCUT);

//添加名称

intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);

//添加图标

intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

//设置Launcher的Uri数据

Intent intentLauncher = new Intent();

intentLauncher.setData(uri);

//添加快捷方式的启动方法

intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentLauncher);

sendBroadcast(intentAddShortcut);

}

当然,你还需要添加一个permission

这里第一个参数Parcelable类型的icon如何获得呢,以下举个例子从Drawable文件夹中获取图片。

Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

Android如何调用系统默认浏览器访问

一、启动android默认浏览器

1.Intent intent= new Intent();

2. intent.setAction("android.intent.action.VIEW");

3. Uri content_url = Uri.parse("http://www.cxybl.com");

4. intent.setData(content_url);

5. startActivity(intent);

这样子,android就可以调用起手机默认的浏览器访问。

二、指定相应的浏览器访问

1、指定android自带的浏览器访问

1.( “com.android.browser”:packagename ;“com.android.browser.BrowserActivity”:启动主activity)

2.

3.

4. Intent intent= new Intent();

5. intent.setAction("android.intent.action.VIEW");

6. Uri content_url = Uri.parse("http://www.cxybl.com");

7. intent.setData(content_url);

8. intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");

9. startActivity(intent);

10.

总结

以上是生活随笔为你收集整理的html5添加到安卓桌面图标,Android向桌面添加快捷方式,使其指向特定的网页的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。