mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 22:57:29 +00:00
Media picker will require Read storage permission
This commit is contained in:
parent
bca38a2645
commit
6005e91d8a
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
|
<!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />-->
|
||||||
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />-->
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
<!--<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
|
<!--<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />-->
|
||||||
|
@ -26,6 +26,7 @@ import awais.instagrabber.R;
|
|||||||
import awais.instagrabber.adapters.MediaItemsAdapter;
|
import awais.instagrabber.adapters.MediaItemsAdapter;
|
||||||
import awais.instagrabber.databinding.LayoutMediaPickerBinding;
|
import awais.instagrabber.databinding.LayoutMediaPickerBinding;
|
||||||
import awais.instagrabber.utils.MediaController;
|
import awais.instagrabber.utils.MediaController;
|
||||||
|
import awais.instagrabber.utils.PermissionUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.viewmodels.MediaPickerViewModel;
|
import awais.instagrabber.viewmodels.MediaPickerViewModel;
|
||||||
|
|
||||||
@ -120,10 +121,10 @@ public class MediaPickerBottomDialogFragment extends BottomSheetDialogFragment {
|
|||||||
if (requestCode == ATTACH_MEDIA_REQUEST_CODE) {
|
if (requestCode == ATTACH_MEDIA_REQUEST_CODE) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
// final boolean hasAttachMediaPerms = PermissionUtils.hasAttachMediaPerms(context);
|
final boolean hasAttachMediaPerms = PermissionUtils.hasAttachMediaPerms(context);
|
||||||
// if (hasAttachMediaPerms) {
|
if (hasAttachMediaPerms) {
|
||||||
viewModel.loadMedia(context);
|
viewModel.loadMedia(context);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +133,10 @@ public class MediaPickerBottomDialogFragment extends BottomSheetDialogFragment {
|
|||||||
setupAlbumPicker();
|
setupAlbumPicker();
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
if (context == null) return;
|
if (context == null) return;
|
||||||
// if (!PermissionUtils.hasAttachMediaPerms(context)) {
|
if (!PermissionUtils.hasAttachMediaPerms(context)) {
|
||||||
// PermissionUtils.requestAttachMediaPerms(this, ATTACH_MEDIA_REQUEST_CODE);
|
PermissionUtils.requestAttachMediaPerms(this, ATTACH_MEDIA_REQUEST_CODE);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
viewModel.loadMedia(context);
|
viewModel.loadMedia(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public class MediaController {
|
|||||||
|
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
// if (PermissionUtils.hasAttachMediaPerms(context)) {
|
if (PermissionUtils.hasAttachMediaPerms(context)) {
|
||||||
cursor = MediaStore.Images.Media.query(context.getContentResolver(),
|
cursor = MediaStore.Images.Media.query(context.getContentResolver(),
|
||||||
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
PROJECTION_PHOTOS,
|
PROJECTION_PHOTOS,
|
||||||
@ -163,7 +163,7 @@ public class MediaController {
|
|||||||
albumEntry.addPhoto(mediaEntry);
|
albumEntry.addPhoto(mediaEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.e(TAG, "loadGalleryAlbums: ", e);
|
Log.e(TAG, "loadGalleryAlbums: ", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -177,7 +177,7 @@ public class MediaController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// if (PermissionUtils.hasAttachMediaPerms(context)) {
|
if (PermissionUtils.hasAttachMediaPerms(context)) {
|
||||||
cursor = MediaStore.Images.Media.query(context.getContentResolver(),
|
cursor = MediaStore.Images.Media.query(context.getContentResolver(),
|
||||||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||||
PROJECTION_VIDEO,
|
PROJECTION_VIDEO,
|
||||||
@ -249,7 +249,7 @@ public class MediaController {
|
|||||||
albumEntry.addPhoto(mediaEntry);
|
albumEntry.addPhoto(mediaEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Log.e(TAG, "loadGalleryAlbums: ", e);
|
Log.e(TAG, "loadGalleryAlbums: ", e);
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -11,31 +11,30 @@ import androidx.core.content.PermissionChecker;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import static android.Manifest.permission.CAMERA;
|
import static android.Manifest.permission.CAMERA;
|
||||||
|
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||||
import static android.Manifest.permission.RECORD_AUDIO;
|
import static android.Manifest.permission.RECORD_AUDIO;
|
||||||
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
import static androidx.core.content.PermissionChecker.checkSelfPermission;
|
||||||
|
|
||||||
public class PermissionUtils {
|
public class PermissionUtils {
|
||||||
public static final String[] AUDIO_RECORD_PERMS = new String[]{RECORD_AUDIO};
|
public static final String[] AUDIO_RECORD_PERMS = new String[]{RECORD_AUDIO};
|
||||||
// public static final String[] ATTACH_MEDIA_PERMS = new String[]{READ_EXTERNAL_STORAGE};
|
public static final String[] ATTACH_MEDIA_PERMS = new String[]{READ_EXTERNAL_STORAGE};
|
||||||
public static final String[] CAMERA_PERMS = new String[]{CAMERA};
|
public static final String[] CAMERA_PERMS = new String[]{CAMERA};
|
||||||
|
|
||||||
public static boolean hasAudioRecordPerms(@NonNull final Context context) {
|
public static boolean hasAudioRecordPerms(@NonNull final Context context) {
|
||||||
return // checkSelfPermission(context, WRITE_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED
|
return checkSelfPermission(context, RECORD_AUDIO) == PermissionChecker.PERMISSION_GRANTED;
|
||||||
// &&
|
|
||||||
checkSelfPermission(context, RECORD_AUDIO) == PermissionChecker.PERMISSION_GRANTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requestAudioRecordPerms(final Fragment fragment, final int requestCode) {
|
public static void requestAudioRecordPerms(final Fragment fragment, final int requestCode) {
|
||||||
fragment.requestPermissions(AUDIO_RECORD_PERMS, requestCode);
|
fragment.requestPermissions(AUDIO_RECORD_PERMS, requestCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static boolean hasAttachMediaPerms(@NonNull final Context context) {
|
public static boolean hasAttachMediaPerms(@NonNull final Context context) {
|
||||||
// return checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
|
return checkSelfPermission(context, READ_EXTERNAL_STORAGE) == PermissionChecker.PERMISSION_GRANTED;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// public static void requestAttachMediaPerms(final Fragment fragment, final int requestCode) {
|
public static void requestAttachMediaPerms(final Fragment fragment, final int requestCode) {
|
||||||
// fragment.requestPermissions(ATTACH_MEDIA_PERMS, requestCode);
|
fragment.requestPermissions(ATTACH_MEDIA_PERMS, requestCode);
|
||||||
// }
|
}
|
||||||
|
|
||||||
public static boolean hasCameraPerms(final Context context) {
|
public static boolean hasCameraPerms(final Context context) {
|
||||||
return ContextCompat.checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
|
return ContextCompat.checkSelfPermission(context, CAMERA) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
Loading…
Reference in New Issue
Block a user