android url 快捷方式,Android向桌面添加快捷方式,使其指向特定的(URL)网页

这段代码展示了如何在Android设备上创建桌面快捷方式,包括设置快捷方式的图标、名称和启动意图URI。Parcelable图标通常从Drawable资源中获取,如示例所示。此功能对于应用自定义快捷方式入口很有用。
摘要由CSDN通过智能技术生成

/*

* 在桌面添加快捷方式

* @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);

}

/*

* 在桌面添加快捷方式

* @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);

}

2.权限设置

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值