gpt4 book ai didi

java - 安装应用程序时无需启动即可自动创建应用程序主页快捷方式吗?

转载 作者:行者123 更新时间:2023-12-02 03:21:10 25 4
gpt4 key购买 nike

我刚刚在 Google 商店下载了一个应用程序,但尚未运行。下载进度完成后,它会自动在我的主屏幕上创建应用程序主页快捷方式。谷歌商店中的每个应用程序都会自动执行此操作吗?如果不?我怎样才能做到这一点?我可以使用此方法在第一次启动应用程序时创建应用程序主页快捷方式:

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();
}

但我想在安装应用程序而不启动时创建一个应用程序主页快捷方式,因为有时用户不会立即在谷歌商店打开我的应用程序,而是在下载进度完成后找到应用程序主页快捷方式打开它。我还有另一个问题。当第一次使用该代码启动应用程序时,我的主屏幕快捷方式的应用程序标题可能会随着手机语言的更改而更改。但我希望它立即改变而不启动。我的问题有解决方案吗?提前致谢。

最佳答案

But I want to create a app home shortcut when installing app without launching

这通常是不可能的。在用户启动您的启动器 Activity 或其他内容使用显式 Intent 启动您的组件之一之前,您的任何代码都不会运行。

关于java - 安装应用程序时无需启动即可自动创建应用程序主页快捷方式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39575815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com