Android实现桌面快捷方式实例代码
短信预约 -IT技能 免费直播动态提醒
Android 快捷方式
使用方式
ShortcutUtils.getInstance().addShortcut(this
, MainActivity2.class
, liveBundle
, "live_Id"
, "看直播"
, "看直播"
, R.drawable.live)
.addShortcut(this
, MainActivity2.class
,vodBundle
, "vod_Id"
, "看回放"
, "看回放"
, R.drawable.vod)
.build();
添加权限
<uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" /> <!-- 添加快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <!-- 移除快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" /> <!-- 查询快捷方式 -->
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher2.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher2.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.WRITE_SETTINGS" />
<uses-permission android:name="org.adw.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="org.adw.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.htc.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.qihoo360.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.qihoo360.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.lge.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.lge.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="net.qihoo.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="net.qihoo.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="org.adwfreak.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="org.adwfreak.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="org.adw.launcher_donut.permission.READ_SETTINGS" />
<uses-permission android:name="org.adw.launcher_donut.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.huawei.launcher3.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.launcher3.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.fede.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.fede.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.sec.android.app.twlauncher.settings.READ_SETTINGS" />
<uses-permission android:name="com.sec.android.app.twlauncher.settings.WRITE_SETTINGS" />
<uses-permission android:name="com.anddoes.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.anddoes.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.tencent.qqlauncher.permission.READ_SETTINGS" />
<uses-permission android:name="com.tencent.qqlauncher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.huawei.launcher2.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.launcher2.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.android.mylauncher.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.mylauncher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.ebproductions.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.ebproductions.android.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.oppo.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.oppo.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.huawei.android.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="telecom.mdesk.permission.READ_SETTINGS" />
<uses-permission android:name="telecom.mdesk.permission.WRITE_SETTINGS" />
<uses-permission android:name="dianxin.permission.ACCESS_LAUNCHER_DATA" />
ShortcutUtils工具类(直接使用)
public class ShortcutUtils {
private static ShortcutUtils shortcutUtils;
private List<ShortcutInfo> shortcutInfos;
private Context mContext;
public static ShortcutUtils getInstance() {
if (shortcutUtils == null) {
synchronized (ShortcutUtils.class) {
if (shortcutUtils == null) {
shortcutUtils = new ShortcutUtils();
}
}
}
return shortcutUtils;
}
private ShortcutUtils() {
shortcutInfos = new ArrayList<>();
}
public ShortcutUtils addShortcut(Context context, Class<?> cls, Bundle bundle, String shortcutId, String shortLabel, String longLabel, @DrawableRes int resId) {
if (shortcutUtils != null && shortcutInfos != null) {
if (Build.VERSION.SDK_INT >= 25) {
mContext = context;
Intent intent = new Intent(context, cls);
intent.putExtra("shortcutArgument", bundle);
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
.setShortLabel(shortLabel)
.setLongLabel(longLabel)
.setIcon(Icon.createWithResource(context, resId))
.setIntent(intent)
.build();
shortcutInfos.add(shortcutInfo);
}
}
return shortcutUtils;
}
public ShortcutUtils addShortcut(Context context, Intent intent, String shortcutId, String shortLabel, String longLabel, @DrawableRes int resId) {
if (Build.VERSION.SDK_INT >= 25) {
mContext = context;
if (shortcutUtils != null && shortcutInfos != null) {
ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, shortcutId)
.setShortLabel(shortLabel)
.setLongLabel(longLabel)
.setIcon(Icon.createWithResource(context, resId))
.setIntent(intent)
.build();
shortcutInfos.add(shortcutInfo);
}
}
return shortcutUtils;
}
public void build() {
if (shortcutInfos != null && shortcutInfos.size() > 0 && mContext != null) {
ShortcutManager systemService = mContext.getSystemService(ShortcutManager.class);
systemService.setDynamicShortcuts(shortcutInfos);
}
}
}
到此这篇关于Android实现桌面快捷方式实例代码的文章就介绍到这了,更多相关Android桌面快捷方式内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341