handle third party Open Image intents

This commit is contained in:
tibbi 2017-04-09 17:13:33 +02:00
parent 32fcf70976
commit 5f4532d8a7
2 changed files with 24 additions and 1 deletions

View File

@ -23,7 +23,16 @@
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:configChanges="orientation"/> android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
</intent-filter>
</activity>
<activity <activity
android:name="com.simplemobiletools.commons.activities.AboutActivity" android:name="com.simplemobiletools.commons.activities.AboutActivity"

View File

@ -36,11 +36,13 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
private val FILE_NAME = "simple-draw.png" private val FILE_NAME = "simple-draw.png"
private val SAVE_IMAGE = 1 private val SAVE_IMAGE = 1
private val OPEN_FILE = 2 private val OPEN_FILE = 2
private val OPEN_FILE_INTENT = 3
private var curPath = "" private var curPath = ""
private var color = 0 private var color = 0
private var strokeWidth = 0f private var strokeWidth = 0f
private var suggestedFileExtension = PNG private var suggestedFileExtension = PNG
private var openFileIntentPath = ""
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -58,6 +60,16 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
color_picker.setOnClickListener { pickColor() } color_picker.setOnClickListener { pickColor() }
undo.setOnClickListener { my_canvas.undo() } undo.setOnClickListener { my_canvas.undo() }
storeStoragePaths() storeStoragePaths()
if (intent?.action == Intent.ACTION_VIEW && intent.data != null) {
val path = intent.data!!.path
if (hasWriteStoragePermission()) {
openPath(path)
} else {
openFileIntentPath = path
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), OPEN_FILE_INTENT)
}
}
} }
override fun onResume() { override fun onResume() {
@ -100,6 +112,8 @@ class MainActivity : SimpleActivity(), MyCanvas.PathsChangedListener {
saveImage() saveImage()
} else if (requestCode == OPEN_FILE) { } else if (requestCode == OPEN_FILE) {
openFile() openFile()
} else if (requestCode == OPEN_FILE_INTENT) {
openPath(openFileIntentPath)
} }
} else { } else {
toast(R.string.no_storage_permissions) toast(R.string.no_storage_permissions)