/*
*首先判断是否有权限
*/
权限处理块
XXPermissions.with(this).permission(ss).request(new OnPermission() {
@Override
public void hasPermission(List<String> granted, boolean isAll) {
}
@Override
public void noPermission(List<String> denied, boolean quick) {
JumpPermissionSet.showHinDialog(ActualCompletionAct.this);
}
});
/*
有权限打开文件夹 , 没权限申请权限
*/
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
//打开文件夹
startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
} catch (android.content.ActivityNotFoundException ex) {
MyToastUtil.showToast(this, "打开文件管理器失败");
}
/*
打开文件夹 选择文件返回 获取文件的url值 获取url值 请看上篇文章 url转换路径
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String path = null;
if (resultCode == RESULT_OK && requestCode == FILE_SELECT_CODE) {
Uri uri = data.getData();
try {
path = PathUtils.getPath(ActualCompletionAct.this, uri);
} catch (Exception e) {
e.printStackTrace();
}
if (!TextUtils.isEmpty(path)) {
File file = new File(path);
if (f != null && f.exists()) {
long l = (f.length() / 1024) / 1024;
if (l > 15) {
MyToastUtil.showToast(this, "只能上传小于15MB的文件");
return;
}else{
网络请求
Uploadfiles(file);
}
}
}
}
}