191
人物
小米手機通過Broadcast無法添加快捷方式
public void createShortCut() {
// boolean exist = hasShortcut();
// 安裝的Intent
Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 快捷名稱
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.name));
// 快捷圖標是否允許重複
shortcut.putExtra("duplicate", false);
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.putExtra("open", 1);//可以不傳
shortcutIntent.setClassName(getPackageName(), "com.test.brc.ui.TestActivity");
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
// 快捷圖片
Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 發送廣播
sendBroadcast(shortcut);
}
請問小米手機為何無法添加快捷方式到桌麵?而華為、三星都可以。如何解決呢
public void createShortCut() { // boolean exist = hasShortcut(); // 安裝的Intent Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 快捷名稱 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.name)); // 快捷圖標是否允許重複 shortcut.putExtra("duplicate", false); Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.putExtra("open", 1);//可以不傳 shortcutIntent.setClassName(getPackageName(), "com.hxdsw.brc.ui.AppStart");//com.hxdsw.brc.ui.AppStart shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); // 快捷圖片 Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); // 發送廣播 sendBroadcast(shortcut); }
最後更新:2017-10-11 18:03:57