英文:
Unable to Read/Write files from Android phone, except AVD in Android Studio
问题
这是我在Android Studio
中用于读取/写入的Java代码。下面的代码片段在AVD模拟器
中可以与Android Studio
一起使用,但在真实的Android手机上无法正常工作。
public static ArrayList<String> dosyaOku1(Context context){
ArrayList<String> itemList = null;
try {
FileInputStream fis = context.openFileInput(DosyaAdi1);
ObjectInputStream ois = new ObjectInputStream(fis);
itemList = (ArrayList<String>) ois.readObject();
} catch (FileNotFoundException e) {
itemList = new ArrayList<>();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
只有读取/写入在真实的Android手机
上无法在Android Studio
中实现。
英文:
Here is my Java code to Read/Write in Android-Studio
. The below snippet works with AVD Emulator
in Andorid Studio
but failed to work in Real Android Phone
public static ArrayList<String> dosyaOku1(Context context){
ArrayList<String> itemList = null;
try {
FileInputStream fis = context.openFileInput(DosyaAdi1);
ObjectInputStream ois = new ObjectInputStream(fis);
itemList = (ArrayList<String>) ois.readObject();
} catch (FileNotFoundException e) {
itemList = new ArrayList<>();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Only the Read/Write can not be implemented for Real Android Phone
in Android-Studio
答案1
得分: 0
如果您的手机系统版本高于棒棒糖(Android 5.0),即使您在manifest.xml文件中添加了权限行,您仍需要在手机中的应用信息中为您的应用程序授予读写存储访问权限。
前往设置 > 应用 > 选择您的应用 > 权限。
然后打开存储“权限”。
英文:
If your phone system above lollipop,even if you add the permissions line in manifest.xml, you need to give your app permission write an read storage access by going to your app info in your phone.
go to your setting > apps > choose your app > permission.
And turn On the storage "permission".
专注分享java语言的经验与见解,让所有开发者获益!
评论