Improved activity not found error

This commit is contained in:
M66B 2021-01-30 11:13:29 +01:00
parent 8408d95848
commit 4e9ee66b34
10 changed files with 50 additions and 38 deletions

View File

@ -445,7 +445,7 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
super.startActivity(intent);
} catch (ActivityNotFoundException 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) {
Log.e(ex);
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))
Helper.viewFAQ(this, 155);
else
ToastEx.makeText(this, getString(R.string.title_no_viewer, intent), Toast.LENGTH_LONG).show();
Helper.reportNoViewer(this, intent);
} catch (Throwable ex) {
Log.e(ex);
ToastEx.makeText(this, Log.formatThrowable(ex), Toast.LENGTH_LONG).show();

View File

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

View File

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

View File

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

View File

@ -2846,7 +2846,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
context.startActivity((Intent) result);
} catch (ActivityNotFoundException 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);
} catch (ActivityNotFoundException ex) {
Log.w(ex);
ToastEx.makeText(context,
context.getString(R.string.title_no_viewer, intent),
Toast.LENGTH_LONG).show();
Helper.reportNoViewer(context, intent);
}
}
}
@ -3494,7 +3492,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
context.startActivity(intent);
} catch (ActivityNotFoundException 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);
} catch (ActivityNotFoundException 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) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex, false);
}
@ -4450,7 +4448,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "view:cid");
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) {
@ -4893,9 +4891,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
PackageManager pm = context.getPackageManager();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R &&
intent.resolveActivity(pm) == null) // system whitelisted
Snackbar.make(parentFragment.getView(),
context.getString(R.string.title_no_viewer, intent), Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
Helper.reportNoViewer(context, intent);
else
context.startActivity(intent);
}

View File

@ -143,7 +143,7 @@ public class FragmentBase extends Fragment {
super.startActivity(intent);
} catch (ActivityNotFoundException 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) {
Log.e(ex);
ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show();
@ -158,7 +158,7 @@ public class FragmentBase extends Fragment {
super.startActivityForResult(intent, requestCode);
} catch (ActivityNotFoundException 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) {
Log.e(ex);
ToastEx.makeText(getContext(), Log.formatThrowable(ex), Toast.LENGTH_LONG).show();

View File

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

View File

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

View File

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

View File

@ -575,15 +575,12 @@ public class Helper {
}
// Check if viewer available
if (ris == null || ris.size() == 0) {
if (ris == null || ris.size() == 0)
if (isTnef(type, null))
viewFAQ(context, 155);
else {
String message = context.getString(R.string.title_no_viewer,
type != null ? type : name != null ? name : file.getName());
ToastEx.makeText(context, message, Toast.LENGTH_LONG).show();
}
} else
else
reportNoViewer(context, intent);
else
context.startActivity(intent);
} else
context.startActivity(intent);
@ -611,7 +608,7 @@ public class Helper {
context.startActivity(intent);
} catch (ActivityNotFoundException 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);
} catch (ActivityNotFoundException 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) {
Log.e(ex);
ToastEx.makeText(context, Log.formatThrowable(ex, false), Toast.LENGTH_LONG).show();
@ -659,7 +656,7 @@ public class Helper {
customTabsIntent.launchUrl(context, uri);
} catch (ActivityNotFoundException 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) {
Log.e(ex);
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));
}
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
static int dp2pixels(Context context, int dp) {