Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
Select image from Source other than Camera fails. - Fixes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
bvolkmer committed Oct 15, 2017
1 parent b67cbca commit fd0b548
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<supports-screens android:xlargeScreens="true"/>

<uses-permission android:name="android.permission.INTERNET"/>
<!--<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>-->
<!--<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:name=".Application"
Expand Down
26 changes: 26 additions & 0 deletions android/src/main/java/de/x4fyr/paiman/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import android.app.Activity
import android.app.AlertDialog
import android.app.Dialog
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.Resources
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.app.ActivityCompat
import android.support.v4.app.DialogFragment
import android.support.v4.content.ContextCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.CardView
import android.support.v7.widget.RecyclerView
Expand Down Expand Up @@ -85,6 +88,10 @@ class MainActivity: BaseActivity(), HasActivityInjector {
private var modelsLock = ReentrantLock()
private var selectedPositions: MutableSet<Int> = hashSetOf()

companion object {
const val READ_EXTERNAL_PERMISSION_REQUEST_CODE = 5477
}

private val actionModeCallback = object: ActionMode.Callback {
/** See [ActionMode.Callback] */
override fun onActionItemClicked(mode: ActionMode, menuItem: MenuItem): Boolean {
Expand Down Expand Up @@ -227,6 +234,25 @@ class MainActivity: BaseActivity(), HasActivityInjector {
updateDialogBuilder().create().show()
}
}
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission
.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE),
READ_EXTERNAL_PERMISSION_REQUEST_CODE)
}
}

/** See [Activity.onRequestPermissionsResult]] */
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
if (requestCode == READ_EXTERNAL_PERMISSION_REQUEST_CODE) {
if (!grantResults.isNotEmpty()
|| grantResults[0] != PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(android.Manifest.permission.READ_EXTERNAL_STORAGE),
READ_EXTERNAL_PERMISSION_REQUEST_CODE)
}
}
}

override fun onResume() {
Expand Down

0 comments on commit fd0b548

Please sign in to comment.