Prevent crash on activity not found

android.provider.MediaStore.RECORD_SOUND was reported to be available while it was not
pull/161/head
M66B 6 years ago
parent 505fdc241a
commit a838cc9d84

@ -20,12 +20,14 @@ package eu.faircode.email;
*/ */
import android.Manifest; import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.os.PowerManager; import android.os.PowerManager;
import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -186,16 +188,26 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
@Override @Override
public void startActivity(Intent intent) { public void startActivity(Intent intent) {
if (Helper.hasAuthentication(this)) try {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); if (Helper.hasAuthentication(this))
super.startActivity(intent); intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivity(intent);
} catch (ActivityNotFoundException ex) {
Log.e(ex);
ToastEx.makeText(this, getString(R.string.title_no_viewer, intent.getAction()), Toast.LENGTH_LONG).show();
}
} }
@Override @Override
public void startActivityForResult(Intent intent, int requestCode) { public void startActivityForResult(Intent intent, int requestCode) {
if (Helper.hasAuthentication(this)) try {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); if (Helper.hasAuthentication(this))
super.startActivityForResult(intent, requestCode); intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException ex) {
Log.e(ex);
ToastEx.makeText(this, getString(R.string.title_no_viewer, intent.getAction()), Toast.LENGTH_LONG).show();
}
} }
@Override @Override

@ -19,6 +19,7 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B) Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/ */
import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -27,6 +28,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
@ -52,16 +54,26 @@ public class FragmentBase extends Fragment {
@Override @Override
public void startActivity(Intent intent) { public void startActivity(Intent intent) {
if (Helper.hasAuthentication(getContext())) try {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); if (Helper.hasAuthentication(getContext()))
super.startActivity(intent); intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivity(intent);
} catch (ActivityNotFoundException ex) {
Log.e(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent.getAction()), Toast.LENGTH_LONG).show();
}
} }
@Override @Override
public void startActivityForResult(Intent intent, int requestCode) { public void startActivityForResult(Intent intent, int requestCode) {
if (Helper.hasAuthentication(getContext())) try {
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); if (Helper.hasAuthentication(getContext()))
super.startActivityForResult(intent, requestCode); intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
super.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException ex) {
Log.e(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent.getAction()), Toast.LENGTH_LONG).show();
}
} }
protected void finish() { protected void finish() {

Loading…
Cancel
Save