android 获取本地存储权限,android - Android Studio-读取本地文件-尽管清单文件中有权限,但权限被拒绝[重复] - 堆栈内存溢出...
我正在尝试使用XmlPullParseFactory解析本地.xml文件。尽管在清单文件中应用了权限,但是我无法访问路径“ /storage/emulated/0/Download/testcards.xml” 。public void parseXML(){XmlPullParserFactory parserFactory;try{parserFactory = XmlPullParser..
我正在尝试使用XmlPullParseFactory解析本地.xml文件。 尽管在清单文件中应用了权限,但是我无法访问路径“ /storage/emulated/0/Download/testcards.xml” 。
public void parseXML(){
XmlPullParserFactory parserFactory;
try{
parserFactory = XmlPullParserFactory.newInstance();
XmlPullParser parser = parserFactory.newPullParser();
InputStream is = new FileInputStream(new File("/storage/emulated/0/Download/testcards.xml"));
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(is,null);
processParsing(parser);
} catch(XmlPullParserException e){
} catch (IOException e) {
}
}
我的清单文件:
package="demoapp1domain.demoapp1">
.....
当我尝试运行程序时,我得到:
java.io.FileNotFoundException:/storage/emulated/0/Download/testcards.xml (权限被拒绝)
这是获取路径的代码:
public void startFileExplorer(View view) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/xml");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(Intent.createChooser(intent, "Select your flashcards .XML-file "), REQUEST_CHOOSER);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CHOOSER:
if (resultCode == RESULT_OK) {
final Uri uri = data.getData();
String myXMLFilePath = uri.getPath();
}
break;
}
}
知道为什么拒绝权限吗?
android {
compileSdkVersion 26
defaultConfig {
applicationId "demoapp1domain.demoapp1"
minSdkVersion 21
targetSdkVersion 26
更多推荐
所有评论(0)