1、分享APP的代码
/**
* 分享APP
* @param packageName:要分享的应用程序包名
*/
private void sharedApp(String packageName) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); // 需要指定意图的数据类型 shareIntent.putExtra(Intent.EXTRA_SUBJECT, "分享"); shareIntent.putExtra(Intent.EXTRA_TEXT, "推荐你使用一个程序" + packageName); shareIntent = Intent.createChooser(shareIntent, "分享"); startActivity(shareIntent); }
2、运行应用程序代码
/** * 运行应用程序 */ private void runApp() { try { PackageInfo info = getPackageManager().getPackageInfo( packname, PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_ACTIVITIES); ActivityInfo[] activityinfos = info.activities; if (activityinfos.length > 0) { ActivityInfo startActivity = activityinfos[0]; Intent intent = new Intent(); intent.setClassName(packname, startActivity.name); Log.i("fuyn", "Liuliangbao:"+packname); startActivity(intent); } else { Toast.makeText(this, "当前应用程序无法启动", 0).show(); } } catch (Exception e) { Toast.makeText(this, "应用程序无法启动", 0).show(); e.printStackTrace(); } }
3、卸载应用
/** * 卸载应用 * @param packname 应用程序包名 */ private void uninstallApp(String packname) { // 需求不能卸载系统的应用程序 if (item.isSystemApp()) { Toast.makeText(this, "系统应用不能被删除", 0).show(); } else { Log.i(TAG, "卸载" + packname); String uristr = "package:" + packname; Uri uri = Uri.parse(uristr); Intent deleteIntent = new Intent(); deleteIntent.setAction(Intent.ACTION_DELETE); deleteIntent.setData(uri); startActivityForResult(deleteIntent, 0); } }