
String SDPATH = Environment.getExternalStorageDirectory().getPath() + "//"
File f = new File(SDPATH +"/Manual/test.pdf")
另外你是不是忘记加权限了<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Android系统中,判断应用有无安装有两种方式:1.根据包名判断,以下为判断代码:
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName))
return false
try {
ApplicationInfo info = context.getPackageManager()
.getApplicationInfo(packageName,
PackageManager.GET_UNINSTALLED_PACKAGES)
return true
} catch (NameNotFoundException e) {
return false
}
}
2. 根据Intent判断,以下为判断代码:
public boolean checkApkExist(Context context, Intent intent) {
List<ResolveInfo>list = context.getPackageManager().queryIntentActivities(intent, 0)
if(list.size() >0){
return true
}
return false
}
public boolean checkApkExist(Context context, String packageName) {
if (packageName == null || “”.equals(packageName)) return false
try {
ApplicationInfo info = context.getPackageManager() .getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES)return true
} catch (NameNotFoundException e) { return false}
}
public boolean checkApkExist(Context context, Intent intent) {
List<ResolveInfo>list = context.getPackageManager()
.queryIntentActivities(intent, 0)
if (list.size() >0) {
return true
}
return false
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)