The document discusses permissions in Android and how they have changed over time. It explains that before Android M, all permissions were granted at install time, but after M, there are normal permissions that are automatically granted and dangerous permissions that must be requested by the app at runtime. It provides examples of normal versus dangerous permissions and discusses how to check for and handle permission requests in code. It also discusses considerations for different device and app versions when dealing with permissions.
2. A Selim Salman
Diversified Android Engineer
@a_selims- Started Android since 2009 in MSc.
- Lived the Diversity of technology.
- Back officially to Android 3 years ago!
3. The Story
Overview about Permissions
M BorderLine
Use the permissions effectively
Nobody can hurt me without my permission.
Mahatma Gandhi
4. What is a permission?
A string that has power!
Defined at: AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
7. After M: RunTime permissions
Types of permissions:
- normal granted
- dangerous request
Permission Groups:
- e.g. CONTACT
Simple, Empowering, Go The extra mile
SDK 23+
11. Check the permission
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (this.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED) {
if (shouldShowRequestPermissionRationale(
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
tvAlert.setText("Hey Man, I need this permission or I ..."); //Explain decently!
}
String[] reqPerms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};
requestPermissions(reqPerms, REQ_CODE_EXT_STORAGE);
return;
}
}
12. Handle the Permission
@@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if(requestCode == REQ_CODE_EXT_STORAGE){
if(grantResults[0] == PackageManager.PERMISSION_GRANTED){
//ToDo write to Disk
} else {
//ToDo Deal with the situation gracefully
}
}
}
13. If not granted
When the app attempts to perform an operation that requires that permission, the
operation will not necessarily cause an exception. Instead, it might return an
empty data set, signal an error, or otherwise exhibit unexpected behavior. For
example, if you query a calendar without permission, the method returns an empty
data set.
http://developer.android.com/preview/features/runtime-permissions.html
https://github.com/aselims/android-RuntimePermissions
14. Devices and Apps
Pre-M device, pre-M app 1 shot
Pre-M device, M app 1 shot
M device, M app RT
M device, pre-M app 1 shot but revoked
handle M APIs:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {}
15. Effective Permissions
Remove the permissions you do not need, How?!
- Google Play Services & 3rd party Libs permissions
- Selectively compile the libs that you need. https://developers.google.
com/android/guides/setup
- Edit Libs from source.
Use Intents! No control over UX