android - 数据仍然保存在内部存储器中,为什么?
问题描述
单击保存按钮时会调用以下方法。但是,数据仍然存储在我的内部存储器中,而不是 sd 卡(外部存储器)中。我是否使用了错误的权限、方法?
public void save(View v)
{
if(isExternalStorageWriteable() && checkPermission(andriod.Manifest.permission.WRITE_EXTERNAL_STORAGE)){
File textfile = new File(Environment.getExternalStorageDirectory(), "Device 1 ");
try{
FileOutputStream fos = new FileOutputStream(textfile);
fos.write(epc.toString().getBytes());
fos.close();
Log.i("State","2");
Toast.makeText(this, "File saved.", Toast.LENGTH_LONG).show();
}
catch (IOException e)
{
e.printStackTrace();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
}
else
{
Log.i("State","4");
Toast.makeText(this, "File not saved.", Toast.LENGTH_LONG).show();
}
}
private boolean isExternalStorageWriteable()
{
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())){
Log.i("State","Yes, it is writeable!");
return true;
}
else{
return false;
}
}
public boolean checkPermission(String permission){
int check = ContextCompat.checkSelfPermission(this,permission);
return (check == PackageManager.PERMISSION_GRANTED);
}
安卓清单
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
解决方案
推荐阅读
- mysql - 如何使用占位符更新 1 行中的 1 列
- javascript - 在迭代时更改我的数组(Javascript)
- java - Flink:左加入带有静态列表的流
- php - 对 phpmail 例程的 Ajax 调用在 ASYNC:FALSE 中有明显的延迟,并且在涉及到新页面的标头时在 ASYNC:TUE 中失败
- javascript - DynamoDB API 时间点备份启用
- javascript - 如果我们在新页面上加载 React 应用程序,如何停止历史记录?
- python - Python 2.7 已弃用,我应该删除它吗?
- pine-script - 最大策略利润的变量值迭代 - Pine 脚本
- reactjs - React reload call api函数不起作用
- mysql - MySQL连接客户端和服务器无法通信,因为它们没有共同的算法