Android 判斷File是否為apk文件
public static Boolean isApkFile(Context context, String filePath) {
String pkg;
try {
PackageManager packageManager = context.getPackageManager();
PackageInfo info = packageManager.getPackageArchiveInfo(filePath, PackageManager.GET_ACTIVITIES);
if (info !=null) {
ApplicationInfo appInfo = info.applicationInfo;
pkg=appInfo.packageName;//得到安裝包名稱
? ? ? ? }else{
pkg="";
}
}catch (Exception e) {
pkg="";
}
return !TextUtils.isEmpty(pkg);
}