android canread,java - On android File canRead() always returns false - Stack Overflow

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值