Skip to content

Most visited

Recently visited

navigation
WatchFace / Wearable / src / com.example.android.wearable.watchface /

CalendarWatchFacePermissionActivity.java

1
package com.example.android.wearable.watchface;
2
 
3
import android.Manifest;
4
import android.content.pm.PackageManager;
5
import android.os.Bundle;
6
import android.support.annotation.NonNull;
7
import android.support.v4.app.ActivityCompat;
8
import android.support.wearable.activity.WearableActivity;
9
import android.util.Log;
10
import android.view.View;
11
 
12
/**
13
 * Simple Activity for displaying Calendar Permission Rationale to user.
14
 */
15
public class CalendarWatchFacePermissionActivity extends WearableActivity {
16
 
17
    private static final String TAG = "PermissionActivity";
18
 
19
    /* Id to identify permission request for calendar. */
20
    private static final int PERMISSION_REQUEST_READ_CALENDAR = 1;
21
 
22
    @Override
23
    protected void onCreate(Bundle savedInstanceState) {
24
        super.onCreate(savedInstanceState);
25
        setContentView(R.layout.activity_calendar_watch_face_permission);
26
        setAmbientEnabled();
27
    }
28
 
29
    public void onClickEnablePermission(View view) {
30
        Log.d(TAG, "onClickEnablePermission()");
31
 
32
        // On 23+ (M+) devices, GPS permission not granted. Request permission.
33
        ActivityCompat.requestPermissions(
34
                this,
35
                new String[]{Manifest.permission.READ_CALENDAR},
36
                PERMISSION_REQUEST_READ_CALENDAR);
37
 
38
    }
39
 
40
    /*
41
     * Callback received when a permissions request has been completed.
42
     */
43
    @Override
44
    public void onRequestPermissionsResult(
45
            int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
46
 
47
        Log.d(TAG, "onRequestPermissionsResult()");
48
 
49
        if (requestCode == PERMISSION_REQUEST_READ_CALENDAR) {
50
            if ((grantResults.length == 1)
51
                    && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
52
                finish();
53
            }
54
        }
55
    }
56
}
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)