gpt4 book ai didi

Android动态快捷方式图标

转载 作者:行者123 更新时间:2023-11-29 15:04:03 32 4
gpt4 key购买 nike

我在使用 Android 7.1.1 的新快捷方式时遇到了一些问题。

第二个可绘制对象没有资源 ID。这是图片和代码 fragment 。

enter image description here

private void createShortcuts(String deviceValue, String tablequery, int pos, String devImage, int index) {
ShortcutManager shortcutManager = mActivity.getSystemService(ShortcutManager.class);

if (index == 0) {

List<ShortcutInfo> scInfo = shortcutManager.getDynamicShortcuts();

Bundle b = new Bundle();
b.putInt("position", pos);
b.putString("table", tablequery);
b.putString("device", devImage);

String add = deviceValue + "_" + tablequery;
ShortcutInfo shortcut = new ShortcutInfo.Builder(mActivity, add)
.setShortLabel(deviceValue) // Shortcut Icon tab
.setLongLabel(deviceValue) // Displayed When Long Pressing On App Icon
.setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone))
.setIntents(new Intent[]{
new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mActivity, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
new Intent(Intent.ACTION_DEFAULT, Uri.EMPTY, mActivity, Device_Detail_Activity.class).putExtras(b)
})
.build();

scInfo.add(shortcut);

shortcutManager.setDynamicShortcuts(scInfo);
} else if (index == 1) {
String remove = deviceValue + "_" + tablequery;
shortcutManager.removeDynamicShortcuts(Arrays.asList(remove));
}
}

我做错了什么?

最佳答案

现在我找到了一个解决方法,但我希望他们会在下一个 API 更新中修复它

这里是剪下来的,看起来不太好,但它有效:

private void createShortcuts(String deviceValue, String tablequery, int pos, String devImage, int index) {
ShortcutManager shortcutManager = mActivity.getSystemService(ShortcutManager.class);
List<ShortcutInfo> scInfo = shortcutManager.getDynamicShortcuts();

if (index == 0) {

Bundle b = new Bundle();
b.putInt("position", pos);
b.putString("table", tablequery);
b.putString("device", devImage);

String add = deviceValue + "_" + tablequery;

if (scInfo.size() == 1) {
ShortcutInfo webShortcut = null, webShortcut1 = null;

webShortcut = new ShortcutInfo.Builder(mActivity, scInfo.get(0).getId())
.setShortLabel(scInfo.get(0).getShortLabel())
.setLongLabel(scInfo.get(0).getLongLabel())
.setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone))
.setIntent(scInfo.get(0).getIntent())
.build();

webShortcut1 = new ShortcutInfo.Builder(mActivity, add)
.setShortLabel(deviceValue) // Shortcut Icon tab
.setLongLabel(deviceValue) // Displayed When Long Pressing On App Icon
.setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone_2))
.setIntents(new Intent[]{
new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mActivity, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
new Intent(Intent.ACTION_DEFAULT, Uri.EMPTY, mActivity, Device_Detail_Activity.class).putExtras(b)
})
.build();

shortcutManager.setDynamicShortcuts(Arrays.asList(webShortcut, webShortcut1));
} else {
ShortcutInfo webShortcut = new ShortcutInfo.Builder(mActivity, add)
.setShortLabel(deviceValue) // Shortcut Icon tab
.setLongLabel(deviceValue) // Displayed When Long Pressing On App Icon
.setIcon(Icon.createWithResource(mActivity, R.drawable.ic_shortcut_phone))
.setIntents(new Intent[]{
new Intent(Intent.ACTION_MAIN, Uri.EMPTY, mActivity, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
new Intent(Intent.ACTION_DEFAULT, Uri.EMPTY, mActivity, Device_Detail_Activity.class).putExtras(b)
})
.build();

shortcutManager.setDynamicShortcuts(Arrays.asList(webShortcut));
}
} else if (index == 1) {
String remove = deviceValue + "_" + tablequery;
shortcutManager.removeDynamicShortcuts(Arrays.asList(remove));
}
}

关于Android动态快捷方式图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40365785/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com