我对 Android 7.1.1 的新快捷方式有一些问题。
第二个drawable没有资源ID。这是和图像和代码片段。
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));
}
}
我究竟做错了什么?