Skip to content

Commit

Permalink
Allow user granting Camera access permission by UI
Browse files Browse the repository at this point in the history
This might solve most of connecting camera device problems like #1.

Signed-off-by: Justin Kim <[email protected]>
  • Loading branch information
Justin Kim committed Sep 6, 2017
1 parent caff638 commit 8ecede7
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8ecede7

Please sign in to comment.