diff --git a/app/src/main/java/org/freedesktop/gstreamer/camera/CameraActivity.java b/app/src/main/java/org/freedesktop/gstreamer/camera/CameraActivity.java index 50ca455..d8b7357 100644 --- a/app/src/main/java/org/freedesktop/gstreamer/camera/CameraActivity.java +++ b/app/src/main/java/org/freedesktop/gstreamer/camera/CameraActivity.java @@ -1,9 +1,13 @@ package org.freedesktop.gstreamer.camera; +import android.Manifest; import android.annotation.SuppressLint; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.os.Bundle; import android.os.Handler; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.util.Log; @@ -25,6 +29,8 @@ */ public class CameraActivity extends AppCompatActivity { + private static final int PERMISSION_REQUEST_CAMERA = 1; + private GstAhc gstAhc; /** * Whether or not the system UI should be auto-hidden after @@ -101,6 +107,14 @@ public boolean onTouch(View view, MotionEvent motionEvent) { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + + ActivityCompat.requestPermissions( + this, + new String[] { Manifest.permission.CAMERA }, + PERMISSION_REQUEST_CAMERA); + return; + } try { gstAhc = GstAhc.init(this); } catch (Exception e) {