Catch ActivityNotFoundException when choosing files.

This commit is contained in:
akwizgran
2022-04-17 12:12:02 +01:00
parent 74a3f54d28
commit 97ba18cfb2
4 changed files with 35 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package org.briarproject.briar.android.conversation;
import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
@@ -121,6 +122,7 @@ import uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt;
import static android.os.Build.VERSION.SDK_INT;
import static android.view.Gravity.RIGHT;
import static android.widget.Toast.LENGTH_LONG;
import static android.widget.Toast.LENGTH_SHORT;
import static androidx.core.app.ActivityOptionsCompat.makeSceneTransitionAnimation;
import static androidx.lifecycle.Lifecycle.State.STARTED;
@@ -774,7 +776,12 @@ public class ConversationActivity extends BriarActivity
@Override
public void onAttachImageClicked() {
launcher.launch("image/*");
try {
launcher.launch("image/*");
} catch (ActivityNotFoundException e) {
Toast.makeText(this, R.string.error_start_activity,
LENGTH_LONG).show();
}
}
private void onImagesChosen(@Nullable List<Uri> uris) {

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.android.removabledrive;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
@@ -68,9 +69,14 @@ public class ReceiveFragment extends Fragment {
scrollView = (ScrollView) v;
progressBar = v.findViewById(R.id.progressBar);
button = v.findViewById(R.id.fileButton);
button.setOnClickListener(view ->
launcher.launch("*/*")
);
button.setOnClickListener(view -> {
try {
launcher.launch("*/*");
} catch (ActivityNotFoundException e) {
Toast.makeText(requireContext(),
R.string.error_start_activity, LENGTH_LONG).show();
}
});
viewModel.getOldTaskResumedEvent()
.observeEvent(getViewLifecycleOwner(), this::onOldTaskResumed);
viewModel.getState()

View File

@@ -1,5 +1,6 @@
package org.briarproject.briar.android.removabledrive;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
@@ -73,9 +74,14 @@ public class SendFragment extends Fragment {
introTextView = v.findViewById(R.id.introTextView);
progressBar = v.findViewById(R.id.progressBar);
button = v.findViewById(R.id.fileButton);
button.setOnClickListener(view ->
launcher.launch(viewModel.getFileName())
);
button.setOnClickListener(view -> {
try {
launcher.launch(viewModel.getFileName());
} catch (ActivityNotFoundException e) {
Toast.makeText(requireContext(),
R.string.error_start_activity, LENGTH_LONG).show();
}
});
viewModel.getOldTaskResumedEvent()
.observeEvent(getViewLifecycleOwner(), this::onOldTaskResumed);

View File

@@ -1,10 +1,12 @@
package org.briarproject.briar.android.settings;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
@@ -23,6 +25,7 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceGroup;
import static android.widget.Toast.LENGTH_LONG;
import static java.util.Objects.requireNonNull;
import static org.briarproject.briar.android.AppModule.getAndroidComponent;
import static org.briarproject.briar.android.TestingConstants.IS_DEBUG_BUILD;
@@ -65,7 +68,12 @@ public class SettingsFragment extends PreferenceFragmentCompat {
prefAvatar = requireNonNull(findPreference(PREF_KEY_AVATAR));
if (viewModel.shouldEnableProfilePictures()) {
prefAvatar.setOnPreferenceClickListener(preference -> {
launcher.launch("image/*");
try {
launcher.launch("image/*");
} catch (ActivityNotFoundException e) {
Toast.makeText(requireContext(),
R.string.error_start_activity, LENGTH_LONG).show();
}
return true;
});
} else {