开发者

Launch installed application with launch activity null

I am using the following code to get a list of installed applications and launch them.It only opens application like calculator or clock.When i try to open applications like contacts or camera it does not work as their launch activity is null.How do i open such applications.

In the below code s[5] points to the camera.

       final PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm
        .getInstalledApplications(PackageManager.GET_META_DATA);


    for (ApplicationInfo packageInfo : packages) 
    {

        s[i]=packageInfo.p开发者_运维知识库ackageName;
        i++;

        Log.d(TAG, "Installed package :" + packageInfo.packageName);
        Log.d(TAG,"Launch Activity :"+ pm.getLaunchIntentForPackage(packageInfo.packageName));

    }


}



    Intent mIntent = getPackageManager().getLaunchIntentForPackage(s[5]);


        try {
            startActivity(mIntent);

        } 
        catch (Exception err) {
            Toast t = Toast.makeText(getApplicationContext(),
                    "Not Found", Toast.LENGTH_SHORT);
            t.show();
        }

}

}


I finally able to solve the issue.The following code launches all the applications.

PackageManager pm = this.getPackageManager();

    setContentView(R.layout.main);
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
    List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0); 
    Collections.sort(appList, new ResolveInfo.DisplayNameComparator(pm)); 

    TextView c=(TextView)findViewById(R.id.textView1);
    for(int i1=0; i1<appList.size(); i1++){ 
            c.setText(c.getText() + "\n" + 
                    "number: " + i1 + "\n" + 
                    "Name: " + appList.get(i1).loadLabel(pm) + "\n" 
                    ); 
    } 


    Intent i11 = new Intent(); 
    i11.setAction(Intent.ACTION_MAIN); 
    i11.addCategory(Intent.CATEGORY_LAUNCHER); 
    i11.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
    i11.setComponent(new ComponentName(appList.get (3).activityInfo.applicationInfo.packageName, appList.get(3).activityInfo.name)); 
    startActivity(i11); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜