私はAndroid 4.4で完全に動作するが、Android 7では動作しないアプリを書いています。 2つのデバイスが根付いています。Android 4.4(API19)とAndroid 7(API24)の間のファイルアクセス権の変更はありますか?
私のアプリケーションの目的は、他のアプリケーションのデータディレクトリ(com.game.origと呼ぼう)からファイルを取得し、アプリケーションディレクトリ(それらをcom.game.cheatと呼ぶ)にコピーすることです。それらを読み取ってから元のディレクトリに書き戻す前に変更してください。
だから私はこのようなディレクトリcom.game.cheatするcom.game.origからファイルをコピーし、「SU」(機能を投げるExecuteAsRootBase.javaが見つかっ) を使用して:ここエンディング
PackageManager m = context.getPackageManager();
String appDir = getPackageDirectory("com.game.orig",m);// /data/user/0/com.game.orig/files/
String localDir = getPackageDirectory(context.getPackageName(),m);// /data/user/0/com.game.cheat/files/
if (ExecuteAsRootBase.canRunRootCommands()) {
ExecuteAsRootBase rootBase = new ExecuteAsRootBase();
Sting fileName="savedgame.dat";
int uid=context.getApplicationInfo().uid;//get the uid (owner) of my app.
//Create localDir (files subdirectory) if not exists
File directory = new File(localDir);
if (!directory.exists()) {
directory.mkdirs();
//adjust file permission (not sure it's realy needed)
rootBase.executecmd("chmod 777 "+ localDir);
rootBase.executecmd("chown " + uid + "." + uid + " " + localDir);
}
//copy file from appDir to localdir using 'su'
rootBase.execute("cp "+ appDir +fileName + " " + localDir)){
//adjust file permission
rootBase.execute("chmod 777 "+ localDir +fileName);
rootBase.execute("chown " + uid + "." + uid + " " + localDir + fileName);
}
を、すべてが正常に動作します:
私はpermsを持つ私のファイルディレクトリを持っています:drwxrwxrwxとu0_a115、グループu0_a115が所有しています。 (/data/data/com.game.cheatの所有者/グループに一致します) と同じ所有者/グループとパーマネントを持つ私のコピーしたファイル:-rwxrwxrwx
コピーしたファイルを開いて読むと、
InputStream input = context.openFileInput(fileName);
openFileInputは例外をスロー:
java.io.FileNotFoundException: /data/user/0/com.game.cheat/files/savedgame.dat (Permission denied)
をそして、これが唯一のAndroid 7.0 API24との電話でocccurs。
誰でも私の了承で何が間違っているのかについていくつかのヒントを持っています。私は最新のAPIで何か新しいことを忘れましたか?
ありがとうございました。
Android 6.0以降では、このためにユーザーからの明示的な許可を求める必要があります。このチェックアウトの詳細を知るにはhttps://developer.android.com/guide/topics/permissions/requesting.html#normal-dangerous –