improving some intent handling for Android 11+
This commit is contained in:
parent
b5ed7944f0
commit
c459cda972
|
@ -56,7 +56,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:5cec51606a'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:8084f88f20'
|
||||
implementation 'joda-time:joda-time:2.10.3'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:c3de1d040a'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.simplemobiletools.contacts.pro.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ClipData
|
||||
import android.content.ContentValues
|
||||
import android.content.Intent
|
||||
|
@ -275,11 +276,7 @@ class EditContactActivity : ContactActivity() {
|
|||
Intent().apply {
|
||||
action = Intent.ACTION_EDIT
|
||||
data = getContactPublicUri(contact!!)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,10 +317,13 @@ class EditContactActivity : ContactActivity() {
|
|||
putExtra("scaleUpIfNeeded", "true")
|
||||
clipData = ClipData("Attachment", arrayOf("text/primaryUri-list"), ClipData.Item(lastPhotoIntentUri))
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
|
||||
try {
|
||||
startActivityForResult(this, INTENT_CROP_PHOTO)
|
||||
} else {
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.no_app_found)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -494,9 +494,9 @@ class EditContactActivity : ContactActivity() {
|
|||
private fun setupRingtone() {
|
||||
contact_ringtone.setOnClickListener {
|
||||
val ringtonePickerIntent = getRingtonePickerIntent()
|
||||
if (ringtonePickerIntent.resolveActivity(packageManager) != null) {
|
||||
try {
|
||||
startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE)
|
||||
} else {
|
||||
} catch (e: Exception) {
|
||||
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
||||
SelectAlarmSoundDialog(this, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
||||
onAlarmPicked = {
|
||||
|
@ -1227,10 +1227,13 @@ class EditContactActivity : ContactActivity() {
|
|||
lastPhotoIntentUri = uri
|
||||
Intent(MediaStore.ACTION_IMAGE_CAPTURE).apply {
|
||||
putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
|
||||
try {
|
||||
startActivityForResult(this, INTENT_TAKE_PHOTO)
|
||||
} else {
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.no_app_found)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1243,10 +1246,13 @@ class EditContactActivity : ContactActivity() {
|
|||
clipData = ClipData("Attachment", arrayOf("text/uri-list"), ClipData.Item(uri))
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||
putExtra(MediaStore.EXTRA_OUTPUT, uri)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
|
||||
try {
|
||||
startActivityForResult(this, INTENT_CHOOSE_PHOTO)
|
||||
} else {
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.no_app_found)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.activities
|
|||
|
||||
import android.app.Activity
|
||||
import android.app.SearchManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
|
@ -269,10 +270,12 @@ class InsertOrEditContactActivity : SimpleActivity(), RefreshContactsListener {
|
|||
putExtra(KEY_EMAIL, email)
|
||||
}
|
||||
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
try {
|
||||
startActivityForResult(this, START_INSERT_ACTIVITY)
|
||||
} else {
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.no_app_found)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -595,9 +595,9 @@ class ViewContactActivity : ContactActivity() {
|
|||
|
||||
contact_ringtone.setOnClickListener {
|
||||
val ringtonePickerIntent = getRingtonePickerIntent()
|
||||
if (ringtonePickerIntent.resolveActivity(packageManager) != null) {
|
||||
try {
|
||||
startActivityForResult(ringtonePickerIntent, INTENT_SELECT_RINGTONE)
|
||||
} else {
|
||||
} catch (e: Exception) {
|
||||
val currentRingtone = contact!!.ringtone ?: getDefaultAlarmSound(RingtoneManager.TYPE_RINGTONE).uri
|
||||
SelectAlarmSoundDialog(this@ViewContactActivity, currentRingtone, AudioManager.STREAM_RING, PICK_RINGTONE_INTENT_ID, RingtoneManager.TYPE_RINGTONE, true,
|
||||
onAlarmPicked = {
|
||||
|
|
|
@ -21,12 +21,7 @@ fun SimpleActivity.startCallIntent(recipient: String) {
|
|||
val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL
|
||||
Intent(action).apply {
|
||||
data = Uri.fromParts("tel", recipient, null)
|
||||
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,11 +58,7 @@ fun Context.editContact(contact: Contact) {
|
|||
fun Context.sendEmailIntent(recipient: String) {
|
||||
Intent(Intent.ACTION_SENDTO).apply {
|
||||
data = Uri.fromParts(KEY_MAILTO, recipient, null)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,11 +67,7 @@ fun Context.sendAddressIntent(address: String) {
|
|||
val uri = Uri.parse("geo:0,0?q=$location")
|
||||
|
||||
Intent(Intent.ACTION_VIEW, uri).apply {
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,11 +80,7 @@ fun Context.openWebsiteIntent(url: String) {
|
|||
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse(website)
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,11 +223,7 @@ fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {
|
|||
|
||||
val uriString = "smsto:${numbers.toString().trimEnd(';')}"
|
||||
Intent(Intent.ACTION_SENDTO, Uri.parse(uriString)).apply {
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,11 +240,7 @@ fun Context.sendEmailToContacts(contacts: ArrayList<Contact>) {
|
|||
Intent(Intent.ACTION_SEND_MULTIPLE).apply {
|
||||
type = "message/rfc822"
|
||||
putExtra(Intent.EXTRA_EMAIL, emails.toTypedArray())
|
||||
if (resolveActivity(packageManager) != null) {
|
||||
startActivity(this)
|
||||
} else {
|
||||
toast(R.string.no_app_found)
|
||||
}
|
||||
launchActivityIntent(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue