ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

Android Studio external storage not available


  • Please log in to reply
Android Studio external storage not available

#1

ligblitz
ligblitz
    Offline
    0
    Rep
    6
    Likes

    Advanced Member

Posts: 107
Threads: 5
Joined: Apr 18, 2016
Credits: 0
Eight years registered
#1
    boolean isExternalStorageAvailable() {
        String extStorageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(extStorageState)) {
            return true;
        }
        return false;
    }
 
this code return false and should true. I can't create new files beacuse of that.
 
I added <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> and <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> to manifest file
 
Code:
        response = (TextView) findViewById(R.id.text_from_file);
        inputText = (EditText) findViewById(R.id.edittext_sum);
        readButton = (Button) findViewById(R.id.read_from_file);
        saveButton = (Button) findViewById(R.id.add_sum);
        readButton.setOnClickListener(new View.OnClickListener() {
            @override
            public void onClick(View v) {
                try {
                    FileInputStream fis = new FileInputStream(myExternalFile);
                    DataInputStream in = new DataInputStream(fis);
                    BufferedReader br = new BufferedReader(new InputStreamReader(in));
                    String strLine;
                    while ((strLine = br.readLine()) != null) {
                        myData = myData + strLine;
                    }
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                inputText.setText(myData);
                response.setText("SampleFile.txt data retrieved from Internal Storage...");
            }
        });
        saveButton.setOnClickListener(new View.OnClickListener() {
            @override
            public void onClick(View v) {
                try {
                    FileOutputStream fos = new FileOutputStream(myExternalFile);
                    fos.write(inputText.getText().toString().getBytes());
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                inputText.setText("");
                response.setText("SampleFile.txt saved to External Storage...");
            }
        });
        if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
            saveButton.setEnabled(false);
            System.out.println("Available: "+isExternalStorageAvailable()+", ReadOnly: "+isExternalStorageReadOnly());
        }
        else {
            myExternalFile = new File(getExternalFilesDir(filepath), filename);
        }

 

I tried all methods from stackoverflow :) Nothing helped. Android emulator external memory = 200mb.


Edited by ligblitz, 08 January 2018 - 11:10 AM.

  • 0

#2

ricci4u
ricci4u
    Offline
    0
    Rep
    0
    Likes

    New Member

Posts: 10
Threads: 0
Joined: Jan 27, 2018
Credits: 0
Six years registered
#2

Man i will look it up, but now i just neded to make one more post


  • 0

#3

sarawast
sarawast
    Offline
    0
    Rep
    0
    Likes

    Member

  • PipPipPip
Posts: 26
Threads: 0
Joined: Jan 30, 2018
Credits: 0
Six years registered
#3
Interesante aporte, gracias

  • 0


 Users browsing this thread: