【问题标题】:Getting an Error : app not found, when i click on the homescreen shortcut in android App出现错误:未找到应用程序,当我单击 android 应用程序中的主屏幕快捷方式时
【发布时间】:2018-11-22 03:18:55
【问题描述】:

我使用主活动中的代码在主屏幕上创建了 android 应用快捷方式

快捷方式创建成功,我可以启动应用程序。

功能也可以正常工作,但是当我单击快捷方式时,会出现找不到应用程序的错误。

请检查我的代码并指导我如何解决这个问题。
这是我的主要活动代码:-

Context context = MainActivity.this;
    SharedPreferences sharedPreferences;
    boolean isAppInstalled = false;

这是我的 onCreate 代码

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        isAppInstalled= sharedPreferences.getBoolean("isAppInstalled", false);
        if(isAppInstalled==false){
            Intent intent1 = new Intent(getApplicationContext(),MainActivity.class);
            intent1.setAction(Intent.ACTION_MAIN);
            Intent intent2 = new Intent();
            intent2.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent1);
            intent2.putExtra(Intent.EXTRA_SHORTCUT_NAME,"My Application");
            intent2.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.ic_launcher));
            intent2.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            getApplicationContext().sendBroadcast(intent2);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putBoolean("isAppInstalled",true);
            editor.commit();

        }

【问题讨论】:

    标签: java android


    【解决方案1】:

    没有人帮助我。 好吧,我解决了自己,谢谢大家,这是我的问题

    我为我的应用创建了启动活动,说明它为什么会在我的代码中使用 意思是用 SplashActivity 改变 MainActivity

    这是正确的代码

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
            isAppInstalled= sharedPreferences.getBoolean("isAppInstalled", false);
            if(isAppInstalled==false){
                Intent intent1 = new Intent(getApplicationContext(),SplashActivity.class);
                intent1.setAction(Intent.ACTION_MAIN);
                Intent intent2 = new Intent();
                intent2.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent1);
                intent2.putExtra(Intent.EXTRA_SHORTCUT_NAME,"My Application");
                intent2.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.ic_launcher));
                intent2.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                getApplicationContext().sendBroadcast(intent2);
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putBoolean("isAppInstalled",true);
                editor.commit();
    
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-27
      • 2013-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      相关资源
      最近更新 更多