mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-10 13:18:09 -05:00
Don't crash when startActivity() fails
Fixes issue 6201
This commit is contained in:
parent
aef6321ecd
commit
5d130b2de1
@ -1,6 +1,7 @@
|
|||||||
package com.fsck.k9.view;
|
package com.fsck.k9.view;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -191,14 +192,14 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case MENU_ITEM_LINK_VIEW: {
|
case MENU_ITEM_LINK_VIEW: {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
getContext().startActivity(intent);
|
startActivityIfAvailable(getContext(), intent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_ITEM_LINK_SHARE: {
|
case MENU_ITEM_LINK_SHARE: {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
intent.setType("text/plain");
|
intent.setType("text/plain");
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||||
getContext().startActivity(intent);
|
startActivityIfAvailable(getContext(), intent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_ITEM_LINK_COPY: {
|
case MENU_ITEM_LINK_COPY: {
|
||||||
@ -243,7 +244,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
// AttachmentProvider
|
// AttachmentProvider
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
}
|
}
|
||||||
getContext().startActivity(intent);
|
startActivityIfAvailable(getContext(), intent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_ITEM_IMAGE_SAVE: {
|
case MENU_ITEM_IMAGE_SAVE: {
|
||||||
@ -291,7 +292,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
case MENU_ITEM_PHONE_CALL: {
|
case MENU_ITEM_PHONE_CALL: {
|
||||||
Uri uri = Uri.parse(WebView.SCHEME_TEL + phoneNumber);
|
Uri uri = Uri.parse(WebView.SCHEME_TEL + phoneNumber);
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
getContext().startActivity(intent);
|
startActivityIfAvailable(getContext(), intent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_ITEM_PHONE_SAVE: {
|
case MENU_ITEM_PHONE_SAVE: {
|
||||||
@ -336,7 +337,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
case MENU_ITEM_EMAIL_SEND: {
|
case MENU_ITEM_EMAIL_SEND: {
|
||||||
Uri uri = Uri.parse(WebView.SCHEME_MAILTO + email);
|
Uri uri = Uri.parse(WebView.SCHEME_MAILTO + email);
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
getContext().startActivity(intent);
|
startActivityIfAvailable(getContext(), intent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MENU_ITEM_EMAIL_SAVE: {
|
case MENU_ITEM_EMAIL_SAVE: {
|
||||||
@ -375,6 +376,14 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startActivityIfAvailable(Context context, Intent intent) {
|
||||||
|
try {
|
||||||
|
context.startActivity(intent);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Toast.makeText(context, R.string.error_activity_not_found, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
switch (view.getId()) {
|
switch (view.getId()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user