Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check runtime permissions #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dependencies {
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'org.mockito:mockito-android:2.6.3'
androidTestImplementation 'org.assertj:assertj-core:1.7.1'
implementation 'com.android.support:support-compat:26.0.2'
}

coveralls {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@

package com.jmolsmobile.landscapevideocapture;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.media.ThumbnailUtils;
import android.os.Bundle;
import android.provider.MediaStore.Video.Thumbnails;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;
Expand All @@ -36,6 +40,9 @@
import com.jmolsmobile.landscapevideocapture.view.RecordingButtonInterface;
import com.jmolsmobile.landscapevideocapture.view.VideoCaptureView;

import java.util.ArrayList;
import java.util.List;

public class VideoCaptureActivity extends Activity implements RecordingButtonInterface, VideoRecorderInterface {

public static final int RESULT_ERROR = 753245;
Expand All @@ -49,6 +56,8 @@ public class VideoCaptureActivity extends Activity implements RecordingButtonInt
private static final String SAVED_RECORDED_BOOLEAN = "com.jmolsmobile.savedrecordedboolean";
protected static final String SAVED_OUTPUT_FILENAME = "com.jmolsmobile.savedoutputfilename";

public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 101;

private boolean mVideoRecorded = false;
VideoFile mVideoFile = null;
private CaptureConfiguration mCaptureConfiguration;
Expand All @@ -64,12 +73,16 @@ public void onCreate(final Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_videocapture);

initializeCaptureConfiguration(savedInstanceState);

if(checkAndRequestPermissions(this)){
setup();
}
}

private void setup(){
mVideoCaptureView = (VideoCaptureView) findViewById(R.id.videocapture_videocaptureview_vcv);
if (mVideoCaptureView == null) return; // Wrong orientation

initializeRecordingUI();
}

Expand Down Expand Up @@ -239,9 +252,59 @@ public Bitmap getVideoThumbnail() {
return thumbnail;
}

public static boolean checkAndRequestPermissions(final Activity context) {
int ExtstorePermission = ContextCompat.checkSelfPermission(context,
Manifest.permission.READ_EXTERNAL_STORAGE);
int cameraPermission = ContextCompat.checkSelfPermission(context,
Manifest.permission.CAMERA);

int microphonePermission = ContextCompat.checkSelfPermission(context,
Manifest.permission.RECORD_AUDIO);

List<String> listPermissionsNeeded = new ArrayList<>();
if (cameraPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.CAMERA);
}
if (ExtstorePermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded
.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}
if (microphonePermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded
.add(Manifest.permission.RECORD_AUDIO);
}

if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(context, listPermissionsNeeded
.toArray(new String[listPermissionsNeeded.size()]),
REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
this.setResult(resultCode, data);
finish();
if(requestCode == REQUEST_ID_MULTIPLE_PERMISSIONS){
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),
"FlagUp Requires Access to Camara.", Toast.LENGTH_SHORT)
.show();
finish();
} else if (ContextCompat.checkSelfPermission(VideoCaptureActivity.this,
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(getApplicationContext(),
"FlagUp Requires Access to Your Storage.",
Toast.LENGTH_SHORT).show();
finish();
} else {
setup();
}
}
else {
finish();
}
}
}