Skip to content

Instantly share code, notes, and snippets.


Sid Patil PatilSiddhesh

View GitHub Profile
PatilSiddhesh / Chainer.kt
Last active Sep 3, 2021
View Chainer.kt
package com.siddroid.folding
fun main() {
// Composing our car
val car = Car.compose(Chain.carEngineType(EngineType.ELECTRIC)
.carOwnerDetails(name = "Android Dev Community",
licenceNo = "API31",
address = "California"
View manifest.xml
<uses-permission android:name="android.permission.READ_CONTACTS"/>
View onRequestPermissionResult.kt
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
when (requestCode) {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show()
} else {
View stringsrationale.xml
<string name="rationale_title">We need permission to read your contacts</string>
<string name="rationale_desc">This app relies on read access to your contacts. We require access to this permission to find your contacts in our database and suggest people you may know. We will not store any contact info in our data base if they are not a part of our platform. For further info read our privacy policy.</string>
View rationale.kt
* Shows rationale dialog for displaying why the app needs permission
* Only shown if the user has denied the permission request previously
private fun showRationaleDialog(
title: String,
message: String,
permission: String,
requestCode: Int
) {
View checkpermission.kt
* Checks permission, if permission has been denied shows rationale for the permission
private fun checkContactsPermission() {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_CONTACTS)
) {
// Check if permission is not granted
Log.d(TAG, "Permission for contacts is not granted")