Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-26488] Android: Fix Ti.Filesystem.requestStoragePermissions for Android 8 and above #10442

Merged
merged 2 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.net.MalformedURLException;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -97,12 +98,13 @@ private boolean hasStoragePermissions()
if (Build.VERSION.SDK_INT < 23) {
return true;
}

Context context = TiApplication.getInstance().getApplicationContext();
if (context.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
return true;
}
return false;

return ((context.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED)
&& (context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED));
}

@Kroll.method
Expand All @@ -112,7 +114,8 @@ public void requestStoragePermissions(@Kroll.argument(optional = true) KrollFunc
return;
}

String[] permissions = new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE };
String[] permissions = new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE,
android.Manifest.permission.WRITE_EXTERNAL_STORAGE };
Activity currentActivity = TiApplication.getInstance().getCurrentActivity();
TiBaseActivity.registerPermissionRequestCallback(TiC.PERMISSION_CODE_EXTERNAL_STORAGE, permissionCallback,
getKrollObject());
Expand Down
4 changes: 2 additions & 2 deletions apidoc/Titanium/Filesystem/Filesystem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ methods:
not check the box "Never ask again" when denying the request. If the user checks the box "Never ask again,"
the user has to manually enable the permission in device settings.

This method requests `Manifest.permission.READ_EXTERNAL_STORAGE`. If you require other permissions, you can also
use <Titanium.Android.requestPermissions>.
This method requests `Manifest.permission.READ_EXTERNAL_STORAGE` and `Manifest.permission.WRITE_EXTERNAL_STORAGE`.
If you require other permissions, you can also use <Titanium.Android.requestPermissions>.
parameters:
- name: callback
summary: Function to call upon user decision to grant storage access
Expand Down