Writing a file to nexus 4 device is not working

I am trying to create a file on device using the following code

private void createFileOnDevice(Boolean append) throws IOException {

        File Root = Environment.getExternalStorageDirectory();
        if (Root.canWrite()) {
            File LogFile = new File(Root, "log.txt");
            FileWriter LogWriter = new FileWriter(LogFile, append);
            out = new BufferedWriter(LogWriter);
            Date date = new Date();
            out.write("Logged at"
                    + String.valueOf(date.getDay() + "-" + date.getHours()
                            + ":" + date.getMinutes() + ":" + date.getSeconds()
                            + "\n"));
        }
    }

The code works fine, when i run on devices which has android version 2.3.5 to 4.3 it creates a file.

But when i run the same app on Nexus 4 , which has latest android version(4.4.2, kitkat), i am unable to create the file. Also, I am not getting any error.

How do i fix it??..

Thanks in advance :):)

Answers


The issue could be the lack of external storage on a nexus 4...

When you are testing, are you testing it in debug mode? If so your operating system will have access to the storage on the nexus 4 and not the phone. Try testing it when the phone has access to the storage and see what happens then...


Need Your Help

how do I capture image from running video in android ?

android image video capture recording

I have a code that records video from camera. I want to use the camera in 2 ways 1. for video recording 2. image capture & transfer to remote android phone. I can not use 1 camera for 2 purpos...

How to allow only one or the other fields be filled in but not both?

ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

I have a product model with 4 attributes called price, price_per_unit, unit and unit_amount. I want to allow either the price attribute to be filled or the other 3 fields but not all 4 of them. Her...