1 case R.id.ll_start: /** 进入程序 */ 2 try { 3 // 获取所有的包信息 4 PackageInfo info = getPackageManager().getPackageInfo( 5 packname, 6 PackageManager.GET_UNINSTALLED_PACKAGES 7 | PackageManager.GET_ACTIVITIES); 8 // 获取所有的activity 9 ActivityInfo[] activityinfos = info.activities; 10 // 因为有些是系统activity所以打不开,得判断下 11 if (activityinfos.length > 0) { 12 // 第一个activity具备启动的能力,用第一个activity打开 13 ActivityInfo startActivity = activityinfos[0]; 14 Intent intent = new Intent(); 15 intent.setClassName(app.getPackname(), startActivity.name); 16 startActivity(intent); 17 } else { 18 Toast.makeText(this, "当前应用程序无法启动", 0).show(); 19 } 20 } catch (NameNotFoundException e) { 21 Toast.makeText(this, "应用程序无法启动", 0).show(); 22 e.printStackTrace(); 23 } 24 break; 25 // 分享程序 26 case R.id.ll_shape: /** 分享 */ 27 Intent shareIntent = new Intent(); 28 shareIntent.setAction(Intent.ACTION_SEND); 29 shareIntent.setType("text/plain"); 30 shareIntent.putExtra(Intent.EXTRA_SUBJECT, "分享"); 31 shareIntent.putExtra(Intent.EXTRA_TEXT, "推荐你使用一个程序" + packname); 32 shareIntent = Intent.createChooser(shareIntent, "分享"); 33 startActivity(shareIntent); 34 break; 35 case R.id.ll_uninstall: /** 卸载 */ 36 if (app.isSystemApp()) { 37 Toast.makeText(this, "系统应用不能被删除", 1).show(); 38 } else { 39 if (!packname.equals(getPackageName())) { 40 String uristr = "package:" + packname; 41 Uri uri = Uri.parse(uristr); 42 Intent deleteIntent = new Intent(); 43 deleteIntent.setAction(Intent.ACTION_DELETE); 44 deleteIntent.setData(uri); 45 startActivityForResult(deleteIntent, 0); 46 return; 47 } else { 48 Toast.makeText(this, "不能卸载自己", 1).show(); 49 return; 50 } 51 52 } 53 break;