mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 11:09:49 +08:00
Use standard actions
This commit is contained in:
@@ -42,27 +42,17 @@ 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) {
|
|
||||||
case "edit":
|
|
||||||
intentAction = Intent.ACTION_EDIT;
|
|
||||||
break;
|
|
||||||
case "send":
|
|
||||||
intentAction = Intent.ACTION_SEND;
|
|
||||||
break;
|
|
||||||
case "view":
|
|
||||||
intentAction = Intent.ACTION_VIEW;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "Invalid action '" + actionExtra + "', using 'view'");
|
Log.e(EmulatorDebug.LOG_TAG, "Invalid action '" + intentAction + "', using 'view'");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final File fileToShare = new File(filePath);
|
final File fileToShare = new File(filePath);
|
||||||
if (!(fileToShare.isFile() && fileToShare.canRead())) {
|
if (!(fileToShare.isFile() && fileToShare.canRead())) {
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
context.startActivity(sendIntent);
|
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[]{
|
||||||
|
Reference in New Issue
Block a user