[Android] [PATCH V2] benchmark: ask write permission before screenshots
Geoffrey Métais
geoffrey at videolan.org
Thu Jul 19 10:45:43 CEST 2018
In the case you need to ask for write permission, you'd better return right
after ActivityCompat.requestPermissions(..) and continue in the callback on
success imho
Le mer. 18 juil. 2018 à 11:22, Duncan McNamara <dcn.mcnamara at gmail.com> a
écrit :
> Adds the permission denied scenario
> ---
> .../gui/video/benchmark/BenchActivity.java | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git
> a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
> b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
> index f5e8b6727..57a62f936 100644
> ---
> a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
> +++
> b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java
> @@ -20,9 +20,11 @@
>
> package org.videolan.vlc.gui.video.benchmark;
>
> +import android.Manifest;
> import android.annotation.TargetApi;
> import android.content.Intent;
> import android.content.pm.ActivityInfo;
> +import android.content.pm.PackageManager;
> import android.graphics.Bitmap;
> import android.graphics.PixelFormat;
> import android.graphics.Point;
> @@ -34,6 +36,8 @@ import android.media.projection.MediaProjectionManager;
> import android.os.Bundle;
> import android.os.Environment;
> import android.os.Handler;
> +import android.support.annotation.NonNull;
> +import android.support.v4.app.ActivityCompat;
> import android.util.DisplayMetrics;
> import android.util.Log;
> import android.view.View;
> @@ -77,6 +81,8 @@ public class BenchActivity extends ShallowVideoPlayer {
>
> private static final int VIRTUAL_DISPLAY_FLAGS = 0;
>
> + private static final int PERMISSION_REQUEST_WRITE = 1;
> +
> private Runnable mTimeOut = null;
>
> private int mWidth;
> @@ -116,6 +122,16 @@ public class BenchActivity extends ShallowVideoPlayer
> {
> super.loadMedia();
> }
>
> + @Override
> + final public void onRequestPermissionsResult(int requestCode,
> @NonNull String[] permissions, @NonNull int[] grantResults) {
> + super.onRequestPermissionsResult(requestCode, permissions,
> grantResults);
> + // checking for permission other than granted
> + if ((requestCode == PERMISSION_REQUEST_WRITE) &&
> + grantResults.length >= 1 && grantResults[0] !=
> PackageManager.PERMISSION_GRANTED) {
> + errorFinish("Failed to get write permission for screenshots");
> + }
> + }
> +
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> /* Crash handler setup */
> @@ -129,6 +145,9 @@ public class BenchActivity extends ShallowVideoPlayer {
> }
> mIsBenchmark = true;
>
> + if (ActivityCompat.checkSelfPermission(this,
> Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
> PackageManager.PERMISSION_GRANTED)
> + ActivityCompat.requestPermissions(this, new
> String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
> PERMISSION_REQUEST_WRITE);
> +
> if (!intent.hasExtra(INTENT_SCREENSHOT_DIR)) {
> errorFinish("Failed to get screenshot directory location");
> }
> --
> 2.18.0
>
> _______________________________________________
> Android mailing list
> Android at videolan.org
> https://mailman.videolan.org/listinfo/android
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/android/attachments/20180719/2065fe04/attachment.html>
More information about the Android
mailing list