对于应用程序,getLaunchIntentForPackage为null

时间:2017-05-04 05:37:54

标签: android gridview launcher package-managers

  1. 我正在警报网格视图中构建已安装的应用。而我正在选择 一些喜欢的应用程序,然后添加到另一个网格视图,如果 我从新的gridview应用程序中选择任何应用程序,它获取Intent值( getLaunchIntentForPackage )为空。

    quick_links_alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                List<String> mArrayProducts = clad.getCheckedItems();
                final QuickLinksGridViewAdaptor selected_apps = new QuickLinksGridViewAdaptor(HomeActivity.this, mArrayProducts);
                gv_shortcut.setAdapter(selected_apps);
                Toast.makeText(getApplicationContext(),"Selected Items-->:"+mArrayProducts,Toast.LENGTH_LONG).show();
                PackageManager pm = HomeActivity.this.getPackageManager();
                Intent quick_intent = new Intent(Intent.ACTION_MAIN, null);
                final List<ResolveInfo> list = pm.queryIntentActivities(quick_intent, PackageManager.PERMISSION_GRANTED);
                gv_shortcut.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        final String packageName = list.get(position).activityInfo.packageName;
                        Intent PackageManagerIntent = getPackageManager().getLaunchIntentForPackage(packageName);
                        if (PackageManagerIntent != null) {
                            startActivity(PackageManagerIntent);
                        }
                        else {
                            Toast.makeText(getApplicationContext(),"NULL",Toast.LENGTH_LONG).show();
                        }
                    }
                });
            }
    In my grid view 8 applications are available.If I click any application its PackageManagerIntent is getting null and 1 and 3 position application its always open google search engine and player application is opening.
    

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题:

String s = mArrayProducts.get(position).getPackageName();
Intent PackageManagerIntent = getPackageManager().getLaunchIntentForPackage(s); NULL
startActivity(PackageManagerIntent);