Skip to content

Most visited

Recently visited

navigation
RuntimePermissions / src / com.example.android.system.runtimepermissions /

RuntimePermissionsFragment.java

1
/*
2
* Copyright 2015 The Android Open Source Project
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.system.runtimepermissions;
18
 
19
import android.os.Build;
20
import android.os.Bundle;
21
import android.support.annotation.Nullable;
22
import android.support.v4.app.Fragment;
23
import android.view.LayoutInflater;
24
import android.view.View;
25
import android.view.ViewGroup;
26
 
27
public class RuntimePermissionsFragment extends Fragment {
28
 
29
    @Nullable
30
    @Override
31
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
32
            Bundle savedInstanceState) {
33
        View root = inflater.inflate(R.layout.fragment_main, null);
34
 
36
        if (Build.VERSION.SDK_INT < 23) {
37
            /*
38
            The contacts permissions have been declared in the AndroidManifest for Android M  and
39
            above only. They are not available on older platforms, so we are hiding the button to
40
            access the contacts database.
41
            This shows how new runtime-only permissions can be added, that do not apply to older
42
            platform versions. This can be useful for automated updates where additional
43
            permissions might prompt the user on upgrade.
44
             */
45
            root.findViewById(R.id.button_contacts).setVisibility(View.GONE);
46
        }
48
 
49
        return root;
50
    }
51
}
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!

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)