主屏幕快捷方式名称在设备语言更改时不会自动更改

时间:2014-03-17 05:25:26

标签: android

我有一个应用程序,我也从代码中创建了一个主屏幕快捷方式。我的应用支持多种语言。当我在手机上更改语言时,应用程序名称会在启动器屏幕中正确更改。但主屏幕快捷方式的名称不会更改。另一方面,如果我首先更改语言然后安装应用程序,主屏幕快捷方式将包含正确的名称。

根据我在这篇文章中的类似问题:

Application title for homescreen shortcut does not change on phone language change

人们建议我这是不可能的,所以我已经从代码中明确地处理了它。但是现在我看到手机上的一些应用程序,名称会随着设备语言的变化而自动更改。有人可以告诉我是否有可能?如果是的话,你能给我一些指示。

1 个答案:

答案 0 :(得分:1)

我终于可以使用以下代码:

public void createShortcut(){

appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);

 if(!isAppInstalled){

    Intent HomeScreenShortCut= new Intent(getApplicationContext(),
            BrowserLauncherActivity.class);

    HomeScreenShortCut.setAction(Intent.ACTION_MAIN);
    HomeScreenShortCut.addCategory(Intent.CATEGORY_LAUNCHER);   
    HomeScreenShortCut.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    HomeScreenShortCut.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    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"); 
    addIntent.putExtra("duplicate", false);
    getApplicationContext().sendBroadcast(addIntent);


    //Make preference true
    SharedPreferences.Editor editor = appPreferences.edit();
    editor.putBoolean("isAppInstalled", true);
    editor.commit();
}   

}

具体来说,这行就是诀窍:

HomeScreenShortCut.addCategory(Intent.CATEGORY_LAUNCHER);

希望它有所帮助。

相关问题