Sync sample prebuilts for mnc-dev
Synced to //developers/samples/android commit 89d2da0f4b. Change-Id: I904da8210517922531d1ac1ba1e747f1c7bf00b3
This commit is contained in:
@@ -54,6 +54,10 @@ import android.widget.ViewAnimator;
|
||||
* {@link Activity#requestPermissions(String[], int)} and the return value checked in {@link
|
||||
* Activity#onRequestPermissionsResult(int, String[], int[])}.
|
||||
* <p>
|
||||
* Before requesting permissions, {@link Activity#shouldShowRequestPermissionRationale(String)}
|
||||
* should be called to provide the user with additional context for the use of permissions if they
|
||||
* have been denied previously.
|
||||
* <p>
|
||||
* If this sample is executed on a device running a platform version below M, all permissions
|
||||
* declared
|
||||
* in the Android manifest file are always granted at install time and cannot be requested at run
|
||||
@@ -102,14 +106,26 @@ public class MainActivity extends SampleActivityBase {
|
||||
// BEGIN_INCLUDE(camera_permission)
|
||||
// Check if the Camera permission is already available.
|
||||
if (PermissionUtil.hasSelfPermission(this, Manifest.permission.CAMERA)) {
|
||||
// Camera permissions is already available, show the camera preview.
|
||||
Log.i(TAG,
|
||||
"CAMERA permission has already been granted. Displaying camera preview.");
|
||||
// Camera permissions is already available, show the camera preview.
|
||||
showCameraPreview();
|
||||
} else {
|
||||
// Camera permission has not been granted.
|
||||
Log.i(TAG, "CAMERA permission has NOT been granted. Requesting permission.");
|
||||
// Camera permission has not been granted. Request it.
|
||||
requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
|
||||
|
||||
// Provide an additional rationale to the user if the permission was not granted
|
||||
// and the user would benefit from additional context for the use of the permission.
|
||||
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
|
||||
Log.i(TAG,
|
||||
"Displaying camera permission rationale to provide additional context.");
|
||||
Toast.makeText(this, R.string.permission_camera_rationale, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
|
||||
// Request Camera permission
|
||||
requestPermissions(new String[]{Manifest.permission.CAMERA},
|
||||
REQUEST_CAMERA);
|
||||
}
|
||||
// END_INCLUDE(camera_permission)
|
||||
|
||||
@@ -128,7 +144,18 @@ public class MainActivity extends SampleActivityBase {
|
||||
// Contact permissions have been granted. Show the contacts fragment.
|
||||
showContactDetails();
|
||||
} else {
|
||||
// Contacts permissions have not been granted.
|
||||
Log.i(TAG, "Contact permissions has NOT been granted. Requesting permission.");
|
||||
|
||||
// Provide an additional rationale to the user if the permission was not granted
|
||||
// and the user would benefit from additional context for the use of the permission.
|
||||
if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {
|
||||
Log.i(TAG,
|
||||
"Displaying contacts permission rationale to provide additional context.");
|
||||
Toast.makeText(this, R.string.permission_contacts_rationale, Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
|
||||
// contact permissions has not been granted (read and write contacts). Request them.
|
||||
requestPermissions(PERMISSIONS_CONTACT, REQUEST_CONTACTS);
|
||||
}
|
||||
|
||||
@@ -61,8 +61,13 @@ public class CameraPreviewFragment extends Fragment {
|
||||
|
||||
// Open an instance of the first camera and retrieve its info.
|
||||
mCamera = getCameraInstance(CAMERA_ID);
|
||||
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(CAMERA_ID, cameraInfo);
|
||||
Camera.CameraInfo cameraInfo = null;
|
||||
|
||||
if (mCamera != null) {
|
||||
// Get camera info only if the camera is available
|
||||
cameraInfo = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(CAMERA_ID, cameraInfo);
|
||||
}
|
||||
|
||||
if (mCamera == null || cameraInfo == null) {
|
||||
// Camera is not available, display error message
|
||||
|
||||
Reference in New Issue
Block a user