I want to start a service that scans a specific directory for sub-directories and files. This is how I start the service in my MainActivity's onCreate method (i use the FAB just for testing purposes):
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), AudioBookLibraryScannerService.class);
intent.putExtra(AudioBookLibraryScannerService.ROOT_DIR, rootDir);
getApplicationContext().startService(intent);
}
});
The rootDir is defined as:
private File extStore = Environment.getExternalStorageDirectory();
private String rootDir = extStore.getAbsolutePath() + "/aubop/";
I also have the permission set in my AndroidManifest.xml:
In the class AudioBookLibraryScannerService I read the passed rootDir as a File:
public static final String ROOT_DIR = "rootDir";
private File rootDir;
[...]
@Override
public void onHandleIntent(Intent intent)
{
[...]
String rootDirPath = intent.getStringExtra(ROOT_DIR);
rootDir = new File(rootDirPath);
Log.e(TAG, rootDirPath.getAbsolutePath());
if(rootDir.canRead()) {
Log.e(TAG, "canRead");
}
[...]
}
The value "canRead" is never traced out, however the traced absolute path is correct.
I also checked the permission of the directory using a file manager. The permissions are set to 771, UID is "root", GID is "everybody". I created the directory on the sdcard using a file explorer and I copied the files into the directory from a network drive using the same file explorer.
Any ideas why the directory is not readable? And as which user is my app running? It looks like the permissions for "others" (the "1" in "771") apply to my app, however I have no idea why.
Thanks!