提前验证是否有APP可以接受一个Intent,这样可以在发送Intent前,避免发送的Intent没有能够接收的APP,导致FC。
方法一:
Intent intent = getInstallAppIntent(activity, appFile);
if (activity.getPackageManager().queryIntentActivities(intent, 0).size() > 0) {
activity.startActivityForResult(intent, REQ_CODE_INSTALL_APP);
}
方法2:
PackageManager pm =mContext.getPackageManager();
ComponentName cn=intent.resolveActivity(pm);
if(cn!=null){
mContext.startActivity(intent);
}else{
//没有支持的app
}
本文介绍两种在Android中提前验证是否有应用能接收特定Intent的方法,避免因无接收者而导致的应用崩溃。
503

被折叠的 条评论
为什么被折叠?



