Sunday, January 10, 2016

File.exists () can not detect the file already exists on the SD card


This post was last edited by the cailingyun0129 on 2013-04-07 14:53:54
Judging by the need to set ringtones in the file system exists in the source RingtoneManager.java where getActualDefaultRingtoneUri (Context context, int type) has increased by the following code:
 
File file = new File (file_path) // file_path SD is known to exist in the file, such as: "/ mnt / sdcard / recordings / test.mp3"
if (file.exists ())
{
return true;
}
else
{
return false;
}


If the point when file_path SD card file This code always returns false (file does exist, and the path and name are not wrong), I do not know why, please dance. If file_path point system memory when files are normal.
Reply:
His top, under the guidance of the great God who ah
Reply:
Are you sure you add the right to limit access to it?
Reply:
The file_path = Environment.getExternalStorageDirectory () + "/" + "recordings / test.mp3"; I feel wrong path
Reply:
quote the second floor KPRF2009 reply:
Are you sure you add the right to limit access to it?
is the code in the source framework plus access Riga how ah? Do not add it!
Reply:
quote 3rd floor comeoverjava reply:
The file_path = Environment.getExternalStorageDirectory () + "/" + "recordings / test.mp3"; I feel is the path not
Use the same method you provided is still return false;
Reply:
File is on the sd card or in the built-in storage?
Reply:
quote, 6th Floor justwandering reply:
file is on the sd card or in the built-in storage?
on the SD card
Reply:
Check the path is not an error
Reply:
Lay the log look getExternalStorageDirectory path

Also must remind you at: file itself may be empty, so the best judge under the former judge file.exists file is empty
And these things are not in the system ringtones on sd card, even though you do not know why this is generally translated into system / under the media's
Reply:
quote 9th floor tanwei4199 reply:
lay log facie getExternalStorageDirectory path

Also must remind you at: file itself may be empty, so the best judge under the former judge file.exists file is empty
And these things are not in the system ringtones on sd card, even though you do not know why this is generally compiled into system / media under
I was set up on the SD card recordings / test.mp3 file as ringtones, log output file_path is: "/ mnt / sdcard / recordings / test.mp3", which should issue it, is calling file.exists when all returns false (); But I standalone application apk call file.exists () returns is normal, and if the file exists returns true, it does not exist return false; but I will add the same piece of code in the source RingtoneManager.java where getActualDefaultRingtoneUri (Context context, int type) in It returns an exception, and only in the SD file returns an exception, the phone memory in the file is normal. Guaizai?
Reply:
Try to add a try catch, this path is on the T card, it is estimated java compiler will add about another processing
Reply:
quote the 10th floor cailingyun0129 reply:
quote 9th floor tanwei4199 reply:
Lay the log look getExternalStorageDirectory path

Also must remind you at: file itself may be empty, so the best judge under the former judge file.exists file is empty
And these things are not in the system ringtones on sd card, even though you do not know why this is, I'm usually compiled into setting system / media under the SD card recordings / test.mp3 file ......


So I think it is caused by mk file local_certificate, if written userId seemingly
not access sd cardYou can continue to look at Baidu
Reply:
Seemingly system privileges can not access the SD card
(not sure if 4.0) after the android 4.0So the framework should be applied to access fails, you can write a simple test apk try is not true of returns
Reply:
quote 13th floor yuleyouxi reply:
seemingly android 4.0 (not sure if 4.0) After the system does not have permission to access the SD card
So the framework should be applied to access fails, you can try to write a simple test apk is not true of the returns
Test apk return is normal
Reply:
file-path: "/mnt/sdcard/recordings/test.mp3" into /sdcard/recordings/test.mp3
Reply:
quote the 14th floor cailingyun0129 reply:
a reference to the 13th floor yuleyouxi reply: looks like the android 4.0 (not sure if 4.0) After the system does not have permission to access the SD Card
So the framework should be applied to access fails, you can try to write a simple test apk is not returned true test apk return is normal


Android version is that you change the framework? Because the system is estimated to be restricted access to sdcard
Reply:
And you encounter the same problem. I also do not understand.
Reply:
I also encountered the same problem, to add permissions
& Lt; uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" / & gt;
Reply:
Why this issue is resolved

No comments:

Post a Comment