Home | History | Annotate | Download | only in com.example.android.system.runtimepermissions
      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 
     35         // BEGIN_INCLUDE(m_only_permission)
     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         }
     47         // END_INCLUDE(m_only_permission)
     48 
     49         return root;
     50     }
     51 }
     52