1*90c8c64dSAndroid Build Coastguard Worker /* 2*90c8c64dSAndroid Build Coastguard Worker * Copyright 2015 The Android Open Source Project 3*90c8c64dSAndroid Build Coastguard Worker * 4*90c8c64dSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*90c8c64dSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*90c8c64dSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*90c8c64dSAndroid Build Coastguard Worker * 8*90c8c64dSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*90c8c64dSAndroid Build Coastguard Worker * 10*90c8c64dSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*90c8c64dSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*90c8c64dSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*90c8c64dSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*90c8c64dSAndroid Build Coastguard Worker * limitations under the License. 15*90c8c64dSAndroid Build Coastguard Worker */ 16*90c8c64dSAndroid Build Coastguard Worker 17*90c8c64dSAndroid Build Coastguard Worker package com.example.android.system.runtimepermissions; 18*90c8c64dSAndroid Build Coastguard Worker 19*90c8c64dSAndroid Build Coastguard Worker import android.os.Build; 20*90c8c64dSAndroid Build Coastguard Worker import android.os.Bundle; 21*90c8c64dSAndroid Build Coastguard Worker import android.support.annotation.Nullable; 22*90c8c64dSAndroid Build Coastguard Worker import android.support.v4.app.Fragment; 23*90c8c64dSAndroid Build Coastguard Worker import android.view.LayoutInflater; 24*90c8c64dSAndroid Build Coastguard Worker import android.view.View; 25*90c8c64dSAndroid Build Coastguard Worker import android.view.ViewGroup; 26*90c8c64dSAndroid Build Coastguard Worker 27*90c8c64dSAndroid Build Coastguard Worker public class RuntimePermissionsFragment extends Fragment { 28*90c8c64dSAndroid Build Coastguard Worker 29*90c8c64dSAndroid Build Coastguard Worker @Nullable 30*90c8c64dSAndroid Build Coastguard Worker @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)31*90c8c64dSAndroid Build Coastguard Worker public View onCreateView(LayoutInflater inflater, ViewGroup container, 32*90c8c64dSAndroid Build Coastguard Worker Bundle savedInstanceState) { 33*90c8c64dSAndroid Build Coastguard Worker View root = inflater.inflate(R.layout.fragment_main, null); 34*90c8c64dSAndroid Build Coastguard Worker 35*90c8c64dSAndroid Build Coastguard Worker // BEGIN_INCLUDE(m_only_permission) 36*90c8c64dSAndroid Build Coastguard Worker if (Build.VERSION.SDK_INT < 23) { 37*90c8c64dSAndroid Build Coastguard Worker /* 38*90c8c64dSAndroid Build Coastguard Worker The contacts permissions have been declared in the AndroidManifest for Android M and 39*90c8c64dSAndroid Build Coastguard Worker above only. They are not available on older platforms, so we are hiding the button to 40*90c8c64dSAndroid Build Coastguard Worker access the contacts database. 41*90c8c64dSAndroid Build Coastguard Worker This shows how new runtime-only permissions can be added, that do not apply to older 42*90c8c64dSAndroid Build Coastguard Worker platform versions. This can be useful for automated updates where additional 43*90c8c64dSAndroid Build Coastguard Worker permissions might prompt the user on upgrade. 44*90c8c64dSAndroid Build Coastguard Worker */ 45*90c8c64dSAndroid Build Coastguard Worker root.findViewById(R.id.button_contacts).setVisibility(View.GONE); 46*90c8c64dSAndroid Build Coastguard Worker } 47*90c8c64dSAndroid Build Coastguard Worker // END_INCLUDE(m_only_permission) 48*90c8c64dSAndroid Build Coastguard Worker 49*90c8c64dSAndroid Build Coastguard Worker return root; 50*90c8c64dSAndroid Build Coastguard Worker } 51*90c8c64dSAndroid Build Coastguard Worker } 52