Open other apps shortcuts from my app programatically android

586 Views Asked by At

To get shortcut list of all apps that are installed on my phone i am doing this and it is working well.

 PackageManager packageManager=getPackageManager();
                Intent shourcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
                List<ResolveInfo> resolveInfos=null;
                resolveInfos=packageManager.queryIntentActivities(shourcutIntent,0);
                List<Intent> intentList=new ArrayList<>();
                int a=0;
                for (ResolveInfo resolveInfo: resolveInfos)
                {
                    Intent intent=new Intent(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_DEFAULT);
                    intent.setComponent(new ComponentName(resolveInfo.activityInfo.applicationInfo.packageName,resolveInfo.activityInfo.name));
                    Log.d("list"+" "+a,""+intent);
                    a++;
                    intentList.add(intent);
                }
                startActivityForResult(intentList.get(11),567);     

And in onActivityResult doing this.

 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode==567)
    {
        if(resultCode== Activity.RESULT_OK)
        {
            Intent intent = (Intent) data.getParcelableExtra("android.intent.extra.shortcut.INTENT");
            if(intent!=null)
            {
                Log.d("getParcelableExtra", "!null");
                String uri = intent.toUri(0);
                try
                {
                    Intent intent1 = Intent.parseUri(uri, 0);
                    intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent1);

                }
                catch (URISyntaxException e)
                {
                    e.printStackTrace();
                }
            }

        }
    }
    }

But the problem is in onActivityResult data.getParcelableExtra("android.intent.extra.shortcut.INTENT") is returning null. Some times it does not return null for example when i launch gmail shortcut but at the same time for Settings shortcut it returns null.
But i want when user select which number to call from contacts shortcut or any other shortcut i want to directly launch calling screen for that contact.
please help.
Thanks in advance.

0

There are 0 best solutions below