diff --git a/packages/clients/android/app/src/main/java/com/cx/goatlin/LoginActivity.kt b/packages/clients/android/app/src/main/java/com/cx/goatlin/LoginActivity.kt index 8f17aef4..69492fd8 100644 --- a/packages/clients/android/app/src/main/java/com/cx/goatlin/LoginActivity.kt +++ b/packages/clients/android/app/src/main/java/com/cx/goatlin/LoginActivity.kt @@ -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 @@ -60,6 +63,14 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks { } } + 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) @@ -164,6 +175,7 @@ class LoginActivity : AppCompatActivity(), LoaderCallbacks { @RequiresApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) override fun onCreateLoader(i: Int, bundle: Bundle?): Loader { + checkAndPromptUserToGrantPermissions(); return CursorLoader(this, // Retrieve data rows for the device user's 'profile' contact. Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,