andriod 怎么读取sd卡中指定的文件
发布时间:2011-07-03 07:10:17 文章来源:www.iduyao.cn 采编人员:星星草
andriod 如何读取sd卡中指定的文件?
以下是读取sd卡中的下载文件,并安装,但是总是提示:文件不存在,重新下载?"
其实sd卡中已有下载的文件了,就是读取不到,什么原因啊?
void installFile(){
File file = null;
// 获取扩展SD卡设备状态
String sDStateString = android.os.Environment.getExternalStorageState();
// 拥有可读可写权限
if (sDStateString.equals(android.os.Environment.MEDIA_MOUNTED)) {
// 获取扩展存储设备的文件目录
File SDFile = android.os.Environment.getExternalStorageDirectory();
// String fileNameNew = (fileName + ".zip").substring(0, fileName
// .length() - 5);
// Log.v("fileNameNew==", fileNameNew);
Log.v("fileNameNew==", "file is read and write");
// 打开文件
// file = new File(SDFile.getAbsolutePath() + File.separator
// + fileName);
file = new File(SDFile.getAbsolutePath() +"/"
+ fileName);
// 判断是否存在,不存在则重新下载
if (!file.exists()) {
Log.v("fileNameNew==,file is exists", "file is not exist");
// myFile.createNewFile();
AlertDialog alertdialog = new AlertDialog.Builder(this)
.setTitle("提示").setMessage("文件不存在,重新下载?")
// .setIcon(R.drawable.quit)
.setPositiveButton("下载",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
setResult(RESULT_OK);// 确定按钮事件
// System.exit(1);
dialog.cancel();
// 调用系统浏览器下载文件
// startActivity(new Intent(
// Intent.ACTION_VIEW, Uri
// .parse(fileUrl)));
downLoadFile(fileUrl);
Log.v("MyActivity,4",
"change into DownLoadFile");
}
}).setNegativeButton("退出",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// 取消按钮事件
// Frame
// frame=(Frame)Desktop.getDisktop().getCurrent();
System.exit(1);
}
}).show();
}else{
Log.v("fileName is exist", "file is exist");
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(intent);
}
} else {
Log.v("fileNameNew==", "file is not read and write");
Toast.makeText(this, "对不起,你没有权限读写该文件!", Toast.LENGTH_SHORT).show();
}
}
------解决方案--------------------
去查api应该有相应的方法
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
谁有google地图校正的数据库或文件?
谁有google地图校正的数据库或文件?
或算法也行
QQ: 15537931
有同样问题的,加我QQ讨论下啊
...
-
请教google map v3自适应容器(浏览器,div等)大小的解决方法?
RT, 谢谢了!!!
------解决方案--------------------
#map_canvas ...
-
求救:MyEclipse6.0开发Android,提示无法找到AVD
我用的MyEclipse6.0搭建android开发环境,创建AVD之后在AVD管理器里面可以看到,运...
-
网站集成google网页搜索的问题…
想在站点中利用google的api提供搜索,高手给指点一下啊,能不能在服务端(asp.net)利用google搜索结果??
...
-
google map服务器部署在局域网,用户联网;用google map API可以开发的系统可以正常运行吗
google map服务器部署在局域网,用户联网;用g...
-
蛋疼~我的chrome居然打不开12306.cn的购票网页
同事的chrome都能打开12306.cn的购票网页,而我的却打不开。
我本本上的chrome版本...
-
google map局域网应用
用google map写了一个项目,内网有的有电脑不能联网,可以访问地图吗?
------解决方案--------------------
...
-
求助GMAP.NET?
RT,为什么自己搭建的WINFORM,加载不了GMAP.NET? 求熟悉者告知 万分感谢
------解决方案--------------------
1、...
-
求google maps api 源代码
有没有google maps api3 的源代码可以下载
------解决方案--------------------
api是谷歌对开发...
-
Google地图接口,怎么算两地的距离
最近做一个项目,需要根据用户填写的两个地名,算出两地之间的距离,我打算使用Google地图,我已经申请...