0
這是我在主屏幕上創建快捷方式的代碼。 Everthing工作正常,但當我點擊主屏幕上的快捷方式時,它顯示「應用程序未安裝」。我想修復它。應用程序未安裝快捷方式
代碼
appPref = getSharedPreferences("isFirstTime", 0);
isFirstTime = appPref.getBoolean("isFirstTime", true);
if (isFirstTime) {
// Create explicit intent which will be used to call Our application
// when some one clicked on short cut
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent intent = new Intent();
// Create Implicit intent and assign Shortcut Application Name, Icon
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Get Quote");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(
getApplicationContext(), R.drawable.ic_launcher));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
// Set preference to inform that we have created shortcut on
// Homescreen
SharedPreferences.Editor editor = appPref.edit();
editor.putBoolean("isFirstTime", false);
editor.commit();
}
}