• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.wearable.runtimepermissions;
18 
19 import android.app.Activity;
20 import android.os.Bundle;
21 import android.support.v4.app.ActivityCompat;
22 import android.support.v7.app.AppCompatActivity;
23 import android.util.Log;
24 import android.view.View;
25 
26 /**
27  * This is a simple splash screen (activity) for giving more details on why the user should approve
28  * phone permissions for storage. If they choose to move forward, the permission screen
29  * is brought up. Either way (approve or disapprove), this will exit to the MainPhoneActivity after
30  * they are finished with their final decision.
31  *
32  * If this activity is started by our service (IncomingRequestPhoneService) it is marked via an
33  * extra (MainPhoneActivity.EXTRA_PROMPT_PERMISSION_FROM_WEAR). That service only starts
34  * this activity if the phone permission hasn't been approved for the data wear is trying to access.
35  * When the user decides within this Activity what to do with the permission request, it closes and
36  * opens the MainPhoneActivity (to maintain the app experience). It also again passes along the same
37  * extra (MainPhoneActivity.EXTRA_PROMPT_PERMISSION_FROM_WEAR) to alert MainPhoneActivity to
38  * send the results of the user's decision to the wear device.
39  */
40 public class WearPermissionRequestActivity extends AppCompatActivity implements
41         ActivityCompat.OnRequestPermissionsResultCallback {
42 
43     private static final String TAG = "WearRationale";
44 
45     @Override
onCreate(Bundle savedInstanceState)46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         setContentView(R.layout.activity_wear_permission_request);
49     }
50 
onClickApprovePermissionRequest(View view)51     public void onClickApprovePermissionRequest(View view) {
52         Log.d(TAG, "onClickApprovePermissionRequest()");
53         setResult(Activity.RESULT_OK);
54         finish();
55     }
56 
onClickDenyPermissionRequest(View view)57     public void onClickDenyPermissionRequest(View view) {
58         Log.d(TAG, "onClickDenyPermissionRequest()");
59         setResult(Activity.RESULT_CANCELED);
60         finish();
61     }
62 }