Use standard actions

This commit is contained in:
Fredrik Fornwall
2017-02-28 00:42:07 +01:00
parent 8a7f93d722
commit 29e62e608f

View File

@@ -42,26 +42,16 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
final String filePath = data.getPath(); final String filePath = data.getPath();
final String contentTypeExtra = intent.getStringExtra("content-type"); final String contentTypeExtra = intent.getStringExtra("content-type");
final boolean useChooser = intent.getBooleanExtra("chooser", false); final boolean useChooser = intent.getBooleanExtra("chooser", false);
final String actionExtra = intent.getAction(); final String intentAction = intent.getAction() == null ? Intent.ACTION_VIEW : intent.getAction();
String intentAction = null; switch (intentAction) {
if (actionExtra == null) { case Intent.ACTION_SEND:
intentAction = Intent.ACTION_VIEW; case Intent.ACTION_VIEW:
} else { // Ok.
switch (actionExtra) { break;
case "edit": default:
intentAction = Intent.ACTION_EDIT; Log.e(EmulatorDebug.LOG_TAG, "Invalid action '" + intentAction + "', using 'view'");
break; break;
case "send":
intentAction = Intent.ACTION_SEND;
break;
case "view":
intentAction = Intent.ACTION_VIEW;
break;
default:
Log.e(EmulatorDebug.LOG_TAG, "Invalid action '" + actionExtra + "', using 'view'");
break;
}
} }
final File fileToShare = new File(filePath); final File fileToShare = new File(filePath);
@@ -72,7 +62,6 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
Intent sendIntent = new Intent(); Intent sendIntent = new Intent();
sendIntent.setAction(intentAction); sendIntent.setAction(intentAction);
Uri uriToShare = Uri.withAppendedPath(Uri.parse("content://com.termux.files/"), filePath);
sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION); sendIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_READ_URI_PERMISSION);
String contentTypeToUse; String contentTypeToUse;
@@ -88,7 +77,7 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
contentTypeToUse = contentTypeExtra; contentTypeToUse = contentTypeExtra;
} }
sendIntent.putExtra(Intent.EXTRA_SUBJECT, fileToShare.getName()); Uri uriToShare = Uri.withAppendedPath(Uri.parse("content://com.termux.files/"), filePath);
if (Intent.ACTION_SEND.equals(intentAction)) { if (Intent.ACTION_SEND.equals(intentAction)) {
sendIntent.putExtra(Intent.EXTRA_STREAM, uriToShare); sendIntent.putExtra(Intent.EXTRA_STREAM, uriToShare);
@@ -101,7 +90,11 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
sendIntent = Intent.createChooser(sendIntent, null).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); sendIntent = Intent.createChooser(sendIntent, null).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} }
context.startActivity(sendIntent); try {
context.startActivity(sendIntent);
} catch (ActivityNotFoundException e) {
Log.e(EmulatorDebug.LOG_TAG, "termux-open: No app handles the url " + data);
}
} }
public static class ContentProvider extends android.content.ContentProvider { public static class ContentProvider extends android.content.ContentProvider {
@@ -114,7 +107,6 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
File file = new File(uri.getPath()); File file = new File(uri.getPath());
String fileName = file.getName();
if (projection == null) { if (projection == null) {
projection = new String[]{ projection = new String[]{