Skip to content

Instantly share code, notes, and snippets.

View PatilSiddhesh's full-sized avatar

Sid Patil PatilSiddhesh

View GitHub Profile
/**
* Checks permission, if permission has been denied shows rationale for the permission
*/
private fun checkContactsPermission() {
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED
) {
// Check if permission is not granted
Log.d(TAG, "Permission for contacts is not granted")
/**
* 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
) {
<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>
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
when (requestCode) {
REQUEST_CONTACTS_STATE -> {
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission granted", Toast.LENGTH_SHORT).show()
} else {
<uses-permission android:name="android.permission.READ_CONTACTS"/>
@PatilSiddhesh
PatilSiddhesh / Chainer.kt
Last active September 3, 2021 09:37
Kotlin-Function-Chaining-with-Composition
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"