Java 在不启动应用程序的情况下安装应用程序时,是否可以自动创建应用程序主页快捷方式?
我刚刚在谷歌商店下载了一个应用程序,还没有运行。下载完成后,它会自动在我的主屏幕上创建应用程序主页快捷方式。谷歌商店上的每个应用程序都会自动做到这一点?如果没有?我该怎么做? 第一次启动应用程序时,我可以使用以下方法创建应用程序主页快捷方式:Java 在不启动应用程序的情况下安装应用程序时,是否可以自动创建应用程序主页快捷方式?,java,android,homescreen,Java,Android,Homescreen,我刚刚在谷歌商店下载了一个应用程序,还没有运行。下载完成后,它会自动在我的主屏幕上创建应用程序主页快捷方式。谷歌商店上的每个应用程序都会自动做到这一点?如果没有?我该怎么做? 第一次启动应用程序时,我可以使用以下方法创建应用程序主页快捷方式: public void createOrUpdateShortcut() { appPreferences = PreferenceManager.getDefaultSharedPreferences(this); isAppInstalled = a
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();
}
但我想在安装应用程序而不启动时创建应用程序主页快捷方式,因为有时用户不会立即在谷歌商店打开我的应用程序,他们会在下载完成后找到应用程序主页快捷方式来打开它。
我还有一个问题。当我第一次使用该代码启动应用程序时,我的主屏幕快捷方式的应用程序标题可以在手机语言更改时更改。但我希望它在不启动的情况下立即更改。
我的问题有解决办法吗?提前谢谢
但我想在安装应用程序而不启动时创建应用程序主页快捷方式
一般来说,这是不可能的。在用户启动启动程序活动或其他使用显式Intent
启动某个组件之前,您的任何代码都不会运行
但我想在安装应用程序而不启动时创建应用程序主页快捷方式
一般来说,这是不可能的。在用户启动您的启动程序活动或其他使用明确的
意图启动您的某个组件之前,您的任何代码都不会运行。我刚刚在google store上下载了一个应用程序,还没有运行它。下载完成后,它会自动在我的主屏幕上创建应用程序主页快捷方式。google store上的每个应用程序都会自动做到这一点?@KhoaMadridista:这取决于主屏幕的实现。我该怎么做@CommonsWare@KhoaMadridista:你怎么能做什么?写一个主屏幕?当下载进度完成时,谷歌商店上的每个应用程序都会自动在主屏幕上创建一个应用程序主快捷方式,所以我不需要做任何事情?我刚刚在谷歌商店下载了一个应用程序,还没有运行它。下载完成后,它会自动在我的主屏幕上创建应用程序主页快捷方式。google store上的每个应用程序都会自动做到这一点?@KhoaMadridista:这取决于主屏幕的实现。我该怎么做@CommonsWare@KhoaMadridista:你怎么能做什么?写一个主屏幕?当下载进度完成时,谷歌商店上的每个应用程序都会自动在主屏幕上创建一个应用程序主快捷方式,这样我就不需要做任何事情了?