android安装、卸载、启动app

安装某个app

/**
 * @param context 上下文
 * @param apkFile 需要安装的app的file对象
 */
 public static void installApp(Context context, File apkFile){  
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    context.startActivity(intent);
 }

卸载某个app

/**
 * @param appPackageName 需要卸载的app的包名
 */
public void uninstall(String appPackageName){  
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_DELETE);
    intent.setData(Uri.parse("package:" + appPackageName));
    startActivityForResult(intent, 0);
}

启动某个app

/**
 * @param appPackageName 需要启动的app的包名
 */
 private void launch(String appPackageName) {
    PackageManager pm = getPackageManager();
        //启动页面的intent
        Intent intent = pm.getLaunchIntentForPackage(appPackageName);
        if (intent != null) {
            startActivity(intent);
        }else{
            Toast.makeText(this, "找不到启动页面", Toast.LENGTH_SHORT).show();
        }
 }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,539评论 25 709
  • Android的安装和启动比较特别,很多机制和直观感受并不一样,如果这里出现误解,就很难透彻理解App的运行,这里...
    蓝灰_q阅读 11,949评论 1 28
  • 1 安装 查看在安装过程中存在的提示信息是否明确,意思是否明确 在安装过程中,点击取消按钮,能否正常退出安装程序,...
    许小小晴阅读 3,579评论 0 0
  • 一、安装 查看在安装过程中存在的提示信息是否明确,意思是否明确 在安装过程中,点击取消按钮,能否正常退出安装程序,...
    宇文臭臭阅读 3,890评论 0 5
  • 寒烟起,一片苍茫。逝水东流,残月笼。飘渺歌,琴声续,浓意情。空愁对,寂空廖。过往无痕,思忆深,感伤存。冷风叹,几度...
    阿仁Cowboy阅读 3,649评论 1 6

友情链接更多精彩内容