Skip to content

Commit

Permalink
Add check before trying to launch contact add intent.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal committed Aug 18, 2022
1 parent 16a4c32 commit a46faeb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
@@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.components.settings.conversation

import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.graphics.PorterDuff
Expand Down Expand Up @@ -82,6 +83,7 @@ import org.thoughtcrime.securesms.util.CommunicationActions
import org.thoughtcrime.securesms.util.ContextUtil
import org.thoughtcrime.securesms.util.ExpirationUtil
import org.thoughtcrime.securesms.util.FeatureFlags
import org.thoughtcrime.securesms.util.IntentUtils
import org.thoughtcrime.securesms.util.Material3OnScrollHelper
import org.thoughtcrime.securesms.util.ViewUtil
import org.thoughtcrime.securesms.util.navigation.safeNavigate
Expand Down Expand Up @@ -477,7 +479,11 @@ class ConversationSettingsFragment : DSLSettingsFragment(
title = DSLSettingsText.from(R.string.ConversationSettingsFragment__add_as_a_contact),
icon = DSLSettingsIcon.from(R.drawable.ic_plus_24),
onClick = {
startActivityForResult(RecipientExporter.export(state.recipient).asAddContactIntent(), REQUEST_CODE_ADD_CONTACT)
try {
startActivityForResult(RecipientExporter.export(state.recipient).asAddContactIntent(), REQUEST_CODE_ADD_CONTACT)
} catch (e: ActivityNotFoundException) {
Toast.makeText(context, R.string.ConversationSettingsFragment__contacts_app_not_found, Toast.LENGTH_SHORT).show()
}
}
)
}
Expand Down
Expand Up @@ -7,11 +7,14 @@
import android.content.pm.LabeledIntent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;

import java.util.List;
import java.util.function.Consumer;

public class IntentUtils {

Expand All @@ -36,5 +39,4 @@ public static boolean isResolvable(@NonNull Context context, @NonNull Intent int
}
return null;
}

}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -4017,6 +4017,8 @@
<string name="NotificationsSettingsFragment__unknown_ringtone">Unknown ringtone</string>

<!-- ConversationSettingsFragment -->
<!-- Error toasted when no activity can handle the add contact intent -->
<string name="ConversationSettingsFragment__contacts_app_not_found">Contacts app not found</string>
<string name="ConversationSettingsFragment__send_message">Send message</string>
<string name="ConversationSettingsFragment__start_video_call">Start video call</string>
<string name="ConversationSettingsFragment__start_audio_call">Start audio call</string>
Expand Down

0 comments on commit a46faeb

Please sign in to comment.