标签:android homescreen installed-applications
有没有办法确定是否有特定的主屏幕快捷方式
存在?或者有没有办法停止出现的Toast消息
何时安装并卸载主屏幕快捷方式?
我的应用程序在设备的主屏幕上安装了一个快捷方式
在某些条件下的启动时间,我不想重复
出现的快捷方式.我也不希望Toast消息出现说
每次都有“快捷方式创建”或“快捷方式已经存在”
设备启动.有没有解决方案来阻止这些Toast消息?
谢谢
解决方法:
它不应该在设备重启时安装.使用以下代码:
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();
}
}
当用户更改语言以反映新语言的名称时,我会更新它.
标签:android,homescreen,installed-applications 来源: https://codeday.me/bug/20190715/1467352.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。