问题
My app writes a file called filename.dat
in the /sdcard folder
I can delete this file from adb in the tablet, using the command
adb shell rm /sdcard/filename.dat
I use this tablet only for development and nothing else, so I have very few apps installed on it, and those are also specific to things that I need to develop, such as file explorer
I tried the same thing in LG Optimus LTE phone that is actively being used, and so has lots of other apps installed, including those needed for personl daily work
When I try the same command,adb shell rm /sdcard/filename.dat
in the LG phone, it refuses to do sorm failed for /sdcard/filename.dat, Permission denied
Why is it behaving this way?
More importantly, in the program that I am testing, it works fine all the time in the Nexus 7, but when I try to run it on the phone, it works fine the first time, but when I do so the second time, one of the variables in the program starts getting NaN values (I have tracked it down to be due to an Infinity/Infinity division taking place on one of the lines), then everytime I execute it again, it shows these NaN values. The program is too long to troubleshoot for someone unfamiliar with it I guess, but it uses AudioTrack and AudioRecord classes to take sound input, perform some FFT and DSP operations on it, then play it back.
What I really need to know is, what is it that is different between tablet and phone, that might be causing a problem like this, and what are the other things I might need to consider?
I initialize the AudioRecord and AudioTrack as
int min = AudioRecord.getMinBufferSize(16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
record = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, min);
int maxJitter = AudioTrack.getMinBufferSize(SAMPLE_FREQUENCY, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.MODE_IN_COMMUNICATION, 16000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, maxJitter, AudioTrack.MODE_STREAM);
I think this might be relevant to this particular program, since using something other than MODE_IN_COMMUNICATION, such as MODE_VOICE_CALL, seems to compile fine but gives similar problems, even in the Nexus 7.
回答1:
You could try System.getenv("EXTERNAL_STORAGE")
to get the external storage directory instead of using /sdcard/
. In my experiences this was the same in most cases. But this should give you a correct output directory every time.
来源:https://stackoverflow.com/questions/19310648/different-behaviour-of-app-in-nexus-7-and-lg-optimus-lte