Java 快捷方式未在android主屏幕上打开应用程序

Java 快捷方式未在android主屏幕上打开应用程序,java,android,Java,Android,我已经在我的android设备上安装了一些应用程序,我开发了一个代码为它们创建一个快捷方式,它们都可以在一个应用程序之外工作,但是如果我在主屏幕上手动拖动应用程序,它就可以工作了,我真的很困惑。。。下一个代码是我用来创建快捷方式的代码 try { //Log.i("shortcut method in androidhelper start","in the shortcutapp on create method "); boolean flag

我已经在我的android设备上安装了一些应用程序,我开发了一个代码为它们创建一个快捷方式,它们都可以在一个应用程序之外工作,但是如果我在主屏幕上手动拖动应用程序,它就可以工作了,我真的很困惑。。。下一个代码是我用来创建快捷方式的代码

try
        {
        //Log.i("shortcut method in androidhelper start","in the shortcutapp on create method ");
        boolean flag =false ;
        int app_id=-1;
        PackageManager p = getPackageManager();
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.addCategory(Intent.CATEGORY_LAUNCHER); 
        List<ResolveInfo> res =p.queryIntentActivities( i,0);
        //System.out.println("the res size is: "+res.size());

        for(int k=0;k<res.size();k++)
        {
        //Log.i("","the application name is: "+res.get(k).activityInfo.loadLabel(p));
        if(res.get(k).activityInfo.loadLabel(p).toString().equals("Kortext")){
        flag = true;
        app_id = k;
        break;
        }
        }

        if(flag)
        {
        ActivityInfo ai = res.get(app_id).activityInfo;
        Intent shortcutIntent = new Intent();
        shortcutIntent.setClassName(ai.packageName, ai.name);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY);
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        // Sets the custom shortcut's title
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Kortext");

        BitmapDrawable bd=(BitmapDrawable)(res.get(app_id).activityInfo.loadIcon(p).getCurrent());
        Bitmap newbit;
        newbit=bd.getBitmap();
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newbit);

        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        sendBroadcast(intent);

        }
        else
        {
    //  throw new UserException(UserException.KErrGeneral,"Application not found");
        }

        }

        catch(ActivityNotFoundException e)
        {
        e.printStackTrace();
        //throw new UserException(UserException.KErrGsmRRNoActivityOnRadioPath,e.getMessage()); 
        }


        catch(Exception e)
        {
        e.printStackTrace();
        //throw new UserException(UserException.KErrGeneral,e.getMessage());

        }
试试看
{
//Log.i(“androidhelper开始时的快捷方式”,“创建方法时的快捷方式应用程序”);
布尔标志=假;
int app_id=-1;
PackageManager p=getPackageManager();
意向i=新意向(意向.行动\主要);
i、 addCategory(意图.类别\发射器);
列表res=p.querytentActivities(i,0);
//System.out.println(“分辨率大小为:“+res.size()”);

对于(intk=0;k我发现了这一点,我还必须将意图更改为新的意图(Intent.ACTION\u MAIN)