93 lines
2.9 KiB
Java
93 lines
2.9 KiB
Java
package st.wow.git.logbook;
|
|
|
|
import java.lang.Runnable;
|
|
import java.lang.String;
|
|
import android.os.Build;
|
|
import android.os.Environment;
|
|
import android.os.Handler;
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
import android.app.Activity;
|
|
import android.app.Fragment;
|
|
import android.app.FragmentManager;
|
|
import android.app.FragmentTransaction;
|
|
import android.content.Intent;
|
|
import android.Manifest;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageManager;
|
|
import android.net.Uri;
|
|
import android.provider.Settings;
|
|
import android.view.View;
|
|
|
|
public class Permissions extends Fragment {
|
|
Context ctx;
|
|
Handler handler;
|
|
final int PERMISSIONS_REQUEST = 1;
|
|
|
|
public Permissions(View view) {
|
|
Log.d("gio", "Permissions()");
|
|
this.ctx = view.getContext();
|
|
this.handler = new Handler(this.ctx.getMainLooper());
|
|
Permissions inst = this;
|
|
handler.post(new Runnable() {
|
|
public void run() {
|
|
Activity act = (Activity)ctx;
|
|
FragmentTransaction ft = act.getFragmentManager().beginTransaction();
|
|
ft.add(inst, "Permissions");
|
|
ft.commitNow();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void onAttach(Context context) {
|
|
super.onAttach(context);
|
|
Log.d("gio", "onAttach()");
|
|
|
|
if (!(context instanceof Activity)) {
|
|
Log.w("gio", "Context is not an Activity");
|
|
return;
|
|
}
|
|
|
|
Activity activity = (Activity) context;
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
|
if (context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
|
|
!= PackageManager.PERMISSION_GRANTED) {
|
|
requestPermissions(
|
|
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
|
|
PERMISSIONS_REQUEST
|
|
);
|
|
}
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
|
|
&& !Environment.isExternalStorageManager()) {
|
|
Log.d("gio", "Requesting all files access");
|
|
Intent intent = new Intent(
|
|
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
|
Uri.parse("package:" + activity.getPackageName())
|
|
);
|
|
if (intent.resolveActivity(activity.getPackageManager()) != null) {
|
|
startActivity(intent);
|
|
} else {
|
|
Intent fallback = new Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
|
|
if (fallback.resolveActivity(activity.getPackageManager()) != null) {
|
|
startActivity(fallback);
|
|
} else {
|
|
Log.e("gio", "No activity found for all files access settings");
|
|
}
|
|
}
|
|
}
|
|
|
|
Log.d("gio", "Loading gio library");
|
|
System.loadLibrary("gio");
|
|
}
|
|
|
|
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
Log.d("gio", "onActivityResult(" + requestCode + "): " + resultCode);
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
}
|
|
}
|