【发布时间】:2016-09-19 14:37:12
【问题描述】:
我刚刚在谷歌商店下载了一个应用程序并没有运行它。下载进度完成后,它会自动在我的主屏幕上创建一个应用程序主页快捷方式。谷歌商店上的每个应用程序都会自动执行此操作?如果不?我怎样才能做到这一点? 我可以在第一次启动应用程序时创建一个应用程序主页快捷方式:
public void createOrUpdateShortcut() {
appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);
String currentLanguage = Locale.getDefault().getDisplayLanguage();
String previousSetLanguage = appPreferences.getString("phoneLanguage", Locale.getDefault().getDisplayLanguage());
if (!previousSetLanguage.equals(currentLanguage)) {
shortcutReinstall = true;
}
if(!isAppInstalled || shortcutReinstall){
Intent HomeScreenShortCut= new Intent(getApplicationContext(),
BrowserLauncherActivity.class);
HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
HomeScreenShortCut.putExtra("duplicate", false);
if(shortcutReinstall) {
Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
String prevAppName = appPreferences.getString("appName", getString(R.string.app_name));
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, prevAppName);
removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(removeIntent);
}
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, HomeScreenShortCut);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
//Make preference true
SharedPreferences.Editor editor = appPreferences.edit();
editor.putBoolean("isAppInstalled", true);
editor.putString("phoneLanguage", currentLanguage);
editor.putString("appName", getString(R.string.app_name));
editor.commit();
}
但是我想在安装应用程序而不启动时创建一个应用程序主页快捷方式,因为有时用户不会立即在谷歌商店打开我的应用程序,他们会在下载进度完成后找到应用程序主页快捷方式来打开它。 我还有另一个问题。当第一次使用该代码启动应用程序时,我的主屏幕快捷方式的应用程序标题可能会随着手机语言的变化而改变。但我希望它立即更改而不启动。 我的问题有解决方案吗?提前致谢。
【问题讨论】:
标签: java android homescreen