Improved activity not found error

pull/194/head
M66B 4 years ago
parent 8408d95848
commit 4e9ee66b34

@ -445,7 +445,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
super.startActivity(intent); super.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(this, getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(this, intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
ToastEx.makeText(this, Log.formatThrowable(ex), Toast.LENGTH_LONG).show(); ToastEx.makeText(this, Log.formatThrowable(ex), Toast.LENGTH_LONG).show();
@ -463,7 +463,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
if (Helper.isTnef(intent.getType(), null)) if (Helper.isTnef(intent.getType(), null))
Helper.viewFAQ(this, 155); Helper.viewFAQ(this, 155);
else else
ToastEx.makeText(this, getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(this, intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
ToastEx.makeText(this, Log.formatThrowable(ex), Toast.LENGTH_LONG).show(); ToastEx.makeText(this, Log.formatThrowable(ex), Toast.LENGTH_LONG).show();

@ -43,7 +43,6 @@ import android.widget.Button;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
@ -427,7 +426,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
context.startActivity(intent); context.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, intent);
} }
} }

@ -45,7 +45,6 @@ import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -289,7 +288,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
context.startActivity(share); context.startActivity(share);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, share), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, share);
} }
} }

@ -49,7 +49,6 @@ import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -863,7 +862,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
context.startActivity(intent); context.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, intent);
} }
} }

@ -2846,7 +2846,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
context.startActivity((Intent) result); context.startActivity((Intent) result);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, result), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, (Intent) result);
} }
} }
} }
@ -3251,9 +3251,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
context.startActivity(intent); context.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, Helper.reportNoViewer(context, intent);
context.getString(R.string.title_no_viewer, intent),
Toast.LENGTH_LONG).show();
} }
} }
} }
@ -3494,7 +3492,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
context.startActivity(intent); context.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, intent);
} }
} }
@ -3578,7 +3576,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Helper.getChooser(context, pick), FragmentMessages.REQUEST_PICK_CONTACT); Helper.getChooser(context, pick), FragmentMessages.REQUEST_PICK_CONTACT);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, pick), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, pick);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex, false); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex, false);
} }
@ -4450,7 +4448,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "view:cid"); }.execute(context, owner, args, "view:cid");
else else
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(context, uri);
} }
private void onMenuButton(final TupleMessageEx message, String button, boolean isChecked) { private void onMenuButton(final TupleMessageEx message, String button, boolean isChecked) {
@ -4893,9 +4891,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
PackageManager pm = context.getPackageManager(); PackageManager pm = context.getPackageManager();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R && if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R &&
intent.resolveActivity(pm) == null) // system whitelisted intent.resolveActivity(pm) == null) // system whitelisted
Snackbar.make(parentFragment.getView(), Helper.reportNoViewer(context, intent);
context.getString(R.string.title_no_viewer, intent), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else else
context.startActivity(intent); context.startActivity(intent);
} }

@ -143,7 +143,7 @@ public class FragmentBase extends Fragment {
super.startActivity(intent); super.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(getContext(), intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show(); ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show();
@ -158,7 +158,7 @@ public class FragmentBase extends Fragment {
super.startActivityForResult(intent, requestCode); super.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(getContext(), intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show(); ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show();

@ -1722,8 +1722,7 @@ public class FragmentCompose extends FragmentBase {
startActivityForResult(intent, REQUEST_RECORD_AUDIO); startActivityForResult(intent, REQUEST_RECORD_AUDIO);
} catch (SecurityException ex) { } catch (SecurityException ex) {
Log.w(ex); Log.w(ex);
Snackbar.make(view, getString(R.string.title_no_viewer, intent), Snackbar.LENGTH_INDEFINITE) Helper.reportNoViewer(getContext(), intent);
.setGestureInsetBottomIgnored(true).show();
} }
} }
@ -2146,8 +2145,7 @@ public class FragmentCompose extends FragmentBase {
startActivityForResult(intent, REQUEST_TAKE_PHOTO); startActivityForResult(intent, REQUEST_TAKE_PHOTO);
} catch (SecurityException ex) { } catch (SecurityException ex) {
Log.w(ex); Log.w(ex);
Snackbar.make(view, getString(R.string.title_no_viewer, intent), Snackbar.LENGTH_LONG) Helper.reportNoViewer(getContext(), intent);
.setGestureInsetBottomIgnored(true).show();
} catch (Throwable ex) { } catch (Throwable ex) {
// / java.lang.IllegalArgumentException: Failed to resolve canonical path for ... // / java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);

@ -23,7 +23,6 @@ import android.content.ActivityNotFoundException;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -208,7 +207,7 @@ public class FragmentDialogBase extends DialogFragment {
super.startActivity(intent); super.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(getContext(), intent);
} }
} }
@ -218,7 +217,7 @@ public class FragmentDialogBase extends DialogFragment {
super.startActivityForResult(intent, requestCode); super.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(getContext(), intent);
} }
} }
} }

@ -440,7 +440,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
getContext().startActivity(app); getContext().startActivity(app);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(getContext(), getString(R.string.title_no_viewer, app), Toast.LENGTH_LONG).show(); Helper.reportNoViewer(getContext(), app);
} }
} }
}); });

@ -575,15 +575,12 @@ public class Helper {
} }
// Check if viewer available // Check if viewer available
if (ris == null || ris.size() == 0) { if (ris == null || ris.size() == 0)
if (isTnef(type, null)) if (isTnef(type, null))
viewFAQ(context, 155); viewFAQ(context, 155);
else { else
String message = context.getString(R.string.title_no_viewer, reportNoViewer(context, intent);
type != null ? type : name != null ? name : file.getName()); else
ToastEx.makeText(context, message, Toast.LENGTH_LONG).show();
}
} else
context.startActivity(intent); context.startActivity(intent);
} else } else
context.startActivity(intent); context.startActivity(intent);
@ -611,7 +608,7 @@ public class Helper {
context.startActivity(intent); context.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri), Toast.LENGTH_LONG).show(); reportNoViewer(context, intent);
} }
} }
@ -636,7 +633,7 @@ public class Helper {
context.startActivity(view); context.startActivity(view);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri), Toast.LENGTH_LONG).show(); reportNoViewer(context, uri);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
ToastEx.makeText(context, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show(); ToastEx.makeText(context, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
@ -659,7 +656,7 @@ public class Helper {
customTabsIntent.launchUrl(context, uri); customTabsIntent.launchUrl(context, uri);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
Log.w(ex); Log.w(ex);
ToastEx.makeText(context, context.getString(R.string.title_no_viewer, uri), Toast.LENGTH_LONG).show(); reportNoViewer(context, uri);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
ToastEx.makeText(context, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show(); ToastEx.makeText(context, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
@ -743,6 +740,31 @@ public class Helper {
return ("Microsoft".equalsIgnoreCase(Build.MANUFACTURER) && "Surface Duo".equals(Build.MODEL)); return ("Microsoft".equalsIgnoreCase(Build.MANUFACTURER) && "Surface Duo".equals(Build.MODEL));
} }
static void reportNoViewer(Context context, Uri uri) {
reportNoViewer(context, new Intent().setData(uri));
}
static void reportNoViewer(Context context, Intent intent) {
StringBuilder sb = new StringBuilder();
String title = intent.getStringExtra(Intent.EXTRA_TITLE);
if (TextUtils.isEmpty(title)) {
Uri data = intent.getData();
if (data == null)
sb.append(intent.toString());
else
sb.append(data.toString());
} else
sb.append(title);
String type = intent.getType();
if (!TextUtils.isEmpty(type))
sb.append(' ').append(type);
String message = context.getString(R.string.title_no_viewer, sb.toString());
ToastEx.makeText(context, message, Toast.LENGTH_LONG).show();
}
// Graphics // Graphics
static int dp2pixels(Context context, int dp) { static int dp2pixels(Context context, int dp) {

Loading…
Cancel
Save