Skip to content

Commit

Permalink
Merge branch 'pr-4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloASilva committed Jan 6, 2022
2 parents 69a4e8a + 29db6b1 commit fc84181
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import android.widget.ArrayAdapter
import android.widget.TextView
import java.util.ArrayList
import android.content.*
import android.content.pm.PackageManager
import android.support.annotation.RequiresApi
import android.support.v4.app.ActivityCompat
import android.support.v4.content.ContextCompat
import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
Expand Down Expand Up @@ -60,6 +63,14 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {
}
}

private fun checkAndPromptUserToGrantPermissions() {
if (ContextCompat.checkSelfPermission(
this,android.Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(
this, arrayOf(android.Manifest.permission.READ_CONTACTS), 1)
}
}

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
val intent = Intent(this, ServerInfoActivity::class.java)
startActivity(intent)
Expand Down Expand Up @@ -164,6 +175,7 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks<Cursor> {

@RequiresApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
override fun onCreateLoader(i: Int, bundle: Bundle?): Loader<Cursor> {
checkAndPromptUserToGrantPermissions();
return CursorLoader(this,
// Retrieve data rows for the device user's 'profile' contact.
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
Expand Down

0 comments on commit fc84181

Please sign in to comment.