diff --git a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 54430c99ca..cba6853fbf 100644 --- a/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -404,6 +404,18 @@ public class FileDisplayActivity extends HookActivity } return; } + case PermissionUtil.PERMISSIONS_CAMERA: { + // If request is cancelled, result arrays are empty. + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + // permission was granted + getFileOperationsHelper() + .uploadFromCamera(this, FileDisplayActivity.REQUEST_CODE__UPLOAD_FROM_CAMERA); + } else { + // permission denied + return; + } + return; + } default: super.onRequestPermissionsResult(requestCode, permissions, grantResults); } diff --git a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java index 0d6c4bf7a0..dee30eaee1 100755 --- a/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java +++ b/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java @@ -23,6 +23,7 @@ package com.owncloud.android.ui.helpers; +import android.Manifest; import android.accounts.Account; import android.app.Activity; import android.content.ActivityNotFoundException; @@ -70,6 +71,7 @@ import com.owncloud.android.ui.events.SyncEventFinished; import com.owncloud.android.utils.ConnectivityUtils; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; +import com.owncloud.android.utils.PermissionUtil; import com.owncloud.android.utils.UriUtils; import org.greenrobot.eventbus.EventBus; @@ -988,7 +990,11 @@ public class FileOperationsHelper { pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); if (pictureIntent.resolveActivity(activity.getPackageManager()) != null) { - activity.startActivityForResult(pictureIntent, requestCode); + if (PermissionUtil.checkSelfPermission(activity, Manifest.permission.CAMERA)) { + activity.startActivityForResult(pictureIntent, requestCode); + } else { + PermissionUtil.requestCameraPermission(activity); + } } else { DisplayUtils.showSnackMessage(activity, "No Camera found"); } @@ -1013,7 +1019,7 @@ public class FileOperationsHelper { } public static String getCapturedImageName() { - return new SimpleDateFormat("Y-MM-dd_HHmmss", Locale.US).format(new Date()) + ".jpg"; + return new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.US).format(new Date()) + ".jpg"; }