当前位置:首页 > 技术心得 > 正文内容

Android调用系统自带的文件管理器进行文件选择

xjtudll10年前 (2016-11-29)技术心得30850

参考资料:

http://blog.csdn.net/zqchn/article/details/8770913

http://www.xuebuyuan.com/929105.html

调用系统自带的文件管理器来选择文件

 

 
 
 
private void showChooser() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
try {
startActivityForResult(intent,EX_FILE_PICKER_RESULT);
} catch (android.content.ActivityNotFoundException ex) {
//Toast.makeText(this, "亲,木有文件管理器啊-_-!!", Toast.LENGTH_SHORT).show();
}

}

在catch,我们可以做更多的操作,比如会跳转到一个下载文件管理器的页面或者等等。

 

 

 

对于返回的数据怎么处理呢。在onActivityResult里处理。

如下:

/** 根据返回选择的文件,来进行操作 **/
 

 

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode != Activity.RESULT_OK) {
Log.e(TAG, "onActivityResult() error, resultCode: " + resultCode);
super.onActivityResult(requestCode, resultCode, data);
return;
}
if (requestCode == EX_FILE_PICKER_RESULT) {
Uri uri = data.getData();
String name = GetPathFromUri4kitkat.getPath(this,uri);
try {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".bin")) {
logNLS("选择了bin文件");
logNLS("文件路径:" + name);
loadFile(name, false);
} else {
logNLS("文件格式错误");
}
}
catch (Exception ignore){

}

}
super.onActivityResult(requestCode, resultCode, data);

}

扫描二维码推送至手机访问。

版权声明:本文由鸟的天空发布,如需转载请注明出处。

本文链接:http://xjtudll.cn/Exp/428/

标签: Android
分享给朋友:

“Android调用系统自带的文件管理器进行文件选择” 的相关文章

Android Warning: Converting to string: TypedValue …

参考资料:   http://stackoverflow.com/questions/4903948/android-resources-converting-to-string-typedvalue-warning   问题:   切换activity...

android warning : Cursor finalized without prior close()

参考资料: http://stackoverflow.com/questions/22355246/cursor-finalized-without-prior-close-warning-what-does-it-mean 问题: LogCat提示:Cursor finalized with...

Storyboard已关联下面的TableView,为什么TabView的Cell显示不出来

问题: Storyboard已关联下面的TableView,为什么TabView的Cell显示不出来 原因及解决办法: 很简单,你的代码没有设置,SB里面的TableViewController要关联一个类,你需要添加好,并且注意下面这两个代理方法的返回值 - (NSInteger)numberO...

Virtual Box Android X86安装:please check you have enough free disk space to install androd x86

原因:下载的iso有问题,换一个iso吧。 当然,前提是你分配的空间确实是足够的,默认8GB肯定是足够的。 我分配了8GB空间,在写入的时候,却提示: Installation failed:please check you have enough free disk space to...

Xcode5 Version与Build设置

Xcode5 Version与Build设置

在ios中,有两种version,一种是 CFBundleVersion ("Bundle Version"),也就是我们看到的Version,另一种是CFBundleShortVersionString ("Bundle version string, short&q...

PowerPCB5.01安装

PowerPCB5.01安装

软件下载地址:http://www.mcu123.com/news/Soft/embsof/pcb/200609/104.html我目前就是用的这个,暂时没发现什么问题。1、安装时选择“Node-locked with FLEXid Key(teal)”  ...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。