From 1b7a860cdffdc9ccf470b8e9473ebbc2b4e741b7 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 16 Mar 2020 22:17:51 +0100 Subject: [PATCH] use Scoped Storage at importing from Android 11 --- .../contacts/pro/activities/MainActivity.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt index d62568a0..a79e6df7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/activities/MainActivity.kt @@ -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() + } } } }