Skip to content

Commit

Permalink
updated...
Browse files Browse the repository at this point in the history
  • Loading branch information
akardas16 committed Nov 19, 2022
1 parent 7cf6da9 commit 7a39255
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package com.akardas.letscheckpermission
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import java.security.Permissions


class LetsCheckPermission(private val context: Context) {

@ChecksSdkIntAtLeast(api = Build.VERSION_CODES.M)
private fun shouldAskPermission(): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
}
Expand Down Expand Up @@ -41,9 +44,6 @@ class LetsCheckPermission(private val context: Context) {
}





}

enum class Status{
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ dependencies {
implementation 'io.github.hariprasanths:bounceview-android:0.2.0'


//implementation project(path: ':LetsCheckPermission')
implementation 'com.github.akardas16:LetPermission:1.0.0'
implementation project(path: ':LetsCheckPermission')
// implementation 'com.github.akardas16:LetPermission:1.0.1'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/java/com/akardas/letpermission/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package com.akardas.letpermission
import android.Manifest
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.akardas.letpermission.databinding.ActivityMainBinding
import com.akardas.letscheckpermission.LetPermissionPreferences
import com.akardas.letscheckpermission.LetsCheckPermission
import com.akardas.letscheckpermission.RequestPermission
import com.akardas.letscheckpermission.Status


Expand All @@ -32,20 +32,18 @@ class MainActivity : AppCompatActivity() {
//Permission denied but you still have chance to show permission pop up again
Toast.makeText(this,"Permission denied!",Toast.LENGTH_LONG).show()
LetPermissionPreferences(this).firstTimeAsking(Manifest.permission.READ_CONTACTS,false)
RequestPermission.withResult(this,Manifest.permission.READ_CONTACTS){ isGranted ->
//You can listen the result from here when user granted o denied permission
Toast.makeText(this,"is granted $isGranted",Toast.LENGTH_LONG).show()
}

//Request READ_CONTACTS Permission
requestPermissionLauncher.launch(Manifest.permission.READ_CONTACTS)
}
Status.NOT_ASKED -> {//Showing Pop up is possible
//you have not yet requested permission
Toast.makeText(this,"no Permission!",Toast.LENGTH_LONG).show()
if (LetPermissionPreferences(this).isFirstTimeAsking(Manifest.permission.READ_CONTACTS)){
LetPermissionPreferences(this).firstTimeAsking(Manifest.permission.READ_CONTACTS,false)
RequestPermission.withResult(this,Manifest.permission.READ_CONTACTS){ isGranted ->
//You can listen the result from here when user granted o denied permission
Toast.makeText(this,"is granted $isGranted",Toast.LENGTH_LONG).show()
}

//Request READ_CONTACTS Permission
requestPermissionLauncher.launch(Manifest.permission.READ_CONTACTS)
}
}
Status.DENIED_WITH_NEVER_ASK -> {
Expand All @@ -60,5 +58,11 @@ class MainActivity : AppCompatActivity() {

}

private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()) { isGranted ->
//You can listen the result from here when user granted o denied permission
Toast.makeText(this,"is granted: $isGranted",Toast.LENGTH_LONG).show()
}


}

0 comments on commit 7a39255

Please sign in to comment.