use Scoped Storage at importing from Android 11

This commit is contained in:
tibbi 2020-03-16 22:17:51 +01:00
parent e262ffecf5
commit 1b7a860cdf
1 changed files with 22 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.contacts.pro.activities
import android.annotation.SuppressLint
import android.app.Activity
import android.app.SearchManager
import android.content.Context
import android.content.Intent
@ -46,6 +47,9 @@ import java.io.FileOutputStream
import java.util.*
class MainActivity : SimpleActivity(), RefreshContactsListener {
private val PICK_IMPORT_SOURCE_INTENT = 1
private val PICK_EXPORT_FILE_INTENT = 1
private var isSearchOpen = false
private var searchMenuItem: MenuItem? = null
private var werePermissionsHandled = false
@ -217,6 +221,13 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
return true
}
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == PICK_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
tryImportContactsFromFile(resultData.data!!)
}
}
private fun storeStateVariables() {
config.apply {
storedTextColor = textColor
@ -446,9 +457,17 @@ class MainActivity : SimpleActivity(), RefreshContactsListener {
}
private fun tryImportContacts() {
handlePermission(PERMISSION_READ_STORAGE) {
if (it) {
importContacts()
if (isQPlus()) {
Intent(Intent.ACTION_GET_CONTENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "text/x-vcard"
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
}
} else {
handlePermission(PERMISSION_READ_STORAGE) {
if (it) {
importContacts()
}
}
}
}