无法从安卓手机读取/写入文件,除了Android Studio中的AVD。

huangapple 未分类评论51阅读模式
英文:

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&lt;String&gt; dosyaOku1(Context context){
            ArrayList&lt;String&gt; itemList = null;
            try {
                FileInputStream fis = context.openFileInput(DosyaAdi1);
                ObjectInputStream ois = new ObjectInputStream(fis);
                itemList = (ArrayList&lt;String&gt;) ois.readObject();
            } catch (FileNotFoundException e) {
                itemList = new ArrayList&lt;&gt;();
                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文件中添加了权限行,您仍需要在手机中的应用信息中为您的应用程序授予读写存储访问权限。

前往设置 > 应用 > 选择您的应用 > 权限。
然后打开存储“权限”。

  • 首先确保您在manifest.xml中授予了读写存储权限
    无法从安卓手机读取/写入文件,除了Android Studio中的AVD。

英文:

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".

  • first make sure that you gave write and read storage permission in your manifest.xml
    无法从安卓手机读取/写入文件,除了Android Studio中的AVD。

huangapple
  • 本文由 发表于 2020年4月4日 02:56:29
  • 转载请务必保留本文链接:https://java.coder-hub.com/61018704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定