<div dir="ltr">In the case you need to ask for write permission, you'd better return right after <span style="color:rgb(33,33,33)">ActivityCompat.requestPermissi</span><span style="color:rgb(33,33,33)">ons(..) and continue in the callback on success imho</span><br><div class="gmail_quote"><div dir="ltr">Le mer. 18 juil. 2018 à 11:22, Duncan McNamara <<a href="mailto:dcn.mcnamara@gmail.com">dcn.mcnamara@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Adds the permission denied scenario<br>
---<br>
.../gui/video/benchmark/BenchActivity.java | 19 +++++++++++++++++++<br>
1 file changed, 19 insertions(+)<br>
<br>
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<br>
index f5e8b6727..57a62f936 100644<br>
--- a/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java<br>
+++ b/vlc-android/src/org/videolan/vlc/gui/video/benchmark/BenchActivity.java<br>
@@ -20,9 +20,11 @@<br>
<br>
package org.videolan.vlc.gui.video.benchmark;<br>
<br>
+import android.Manifest;<br>
import android.annotation.TargetApi;<br>
import android.content.Intent;<br>
import <a href="http://android.content.pm" target="_blank">android.content.pm</a>.ActivityInfo;<br>
+import <a href="http://android.content.pm" target="_blank">android.content.pm</a>.PackageManager;<br>
import android.graphics.Bitmap;<br>
import android.graphics.PixelFormat;<br>
import android.graphics.Point;<br>
@@ -34,6 +36,8 @@ import android.media.projection.MediaProjectionManager;<br>
import android.os.Bundle;<br>
import android.os.Environment;<br>
import android.os.Handler;<br>
+import android.support.annotation.NonNull;<br>
+import android.support.v4.app.ActivityCompat;<br>
import android.util.DisplayMetrics;<br>
import android.util.Log;<br>
import android.view.View;<br>
@@ -77,6 +81,8 @@ public class BenchActivity extends ShallowVideoPlayer {<br>
<br>
private static final int VIRTUAL_DISPLAY_FLAGS = 0;<br>
<br>
+ private static final int PERMISSION_REQUEST_WRITE = 1;<br>
+<br>
private Runnable mTimeOut = null;<br>
<br>
private int mWidth;<br>
@@ -116,6 +122,16 @@ public class BenchActivity extends ShallowVideoPlayer {<br>
super.loadMedia();<br>
}<br>
<br>
+ @Override<br>
+ final public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {<br>
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);<br>
+ // checking for permission other than granted<br>
+ if ((requestCode == PERMISSION_REQUEST_WRITE) &&<br>
+ grantResults.length >= 1 && grantResults[0] != PackageManager.PERMISSION_GRANTED) {<br>
+ errorFinish("Failed to get write permission for screenshots");<br>
+ }<br>
+ }<br>
+<br>
@Override<br>
protected void onCreate(Bundle savedInstanceState) {<br>
/* Crash handler setup */<br>
@@ -129,6 +145,9 @@ public class BenchActivity extends ShallowVideoPlayer {<br>
}<br>
mIsBenchmark = true;<br>
<br>
+ if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)<br>
+ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_WRITE);<br>
+<br>
if (!intent.hasExtra(INTENT_SCREENSHOT_DIR)) {<br>
errorFinish("Failed to get screenshot directory location");<br>
}<br>
--<br>
2.18.0<br>
<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</blockquote></div></div>