标签:android style blog io color ar os 使用 sp
一、安装APK文件
/** * 安装apk * * @param file 要安装的APK文件 */ private void install(File file) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); finish(); startActivity(intent); }
二、分享功能实现
Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("text/plain"); // 需要指定意图的数据类型 shareIntent.putExtra(Intent.EXTRA_SUBJECT, "分享"); shareIntent.putExtra(Intent.EXTRA_TEXT, "推荐你使用一个程序" + item.getAppname()); shareIntent = Intent.createChooser(shareIntent, "分享"); startActivity(shareIntent);
三、卸载程序
String uristr = "package:" + packname; Uri uri = Uri.parse(uristr); Intent deleteIntent = new Intent(); deleteIntent.setAction(Intent.ACTION_DELETE); deleteIntent.setData(uri); startActivityForResult(deleteIntent, 0);
四、运行应用程序
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); startActivity(intent); } else { Toast.makeText(this, "当前应用程序无法启动", 0).show(); } } catch (Exception e) { Toast.makeText(this, "应用程序无法启动", 0).show(); e.printStackTrace(); }
标签:android style blog io color ar os 使用 sp
原文地址:http://www.cnblogs.com/fuyanan/p/4089814.html