Skip to content

Commit 5437277

Browse files
committed
Enable Sharing a file from Files app
1 parent 19d76d4 commit 5437277

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@
114114
android:scheme="content"/>
115115
</intent-filter>
116116

117+
<!-- This filter works, when sharing a hex file from Files app -->
118+
<!-- https://developer.android.com/training/sharing/receive#update-manifest -->
119+
<intent-filter>
120+
<action android:name="android.intent.action.SEND"/>
121+
<category android:name="android.intent.category.DEFAULT"/>
122+
<category android:name="android.intent.category.BROWSABLE"/>
123+
<data android:mimeType="application/octet-stream" />
124+
</intent-filter>
125+
117126
</activity>
118127
<activity
119128
android:name=".ui.activity.NotificationActivity"

app/src/main/java/com/samsung/microbit/ui/activity/ProjectActivity.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import java.io.InputStream;
7878
import java.io.InputStreamReader;
7979
import java.io.OutputStream;
80+
import java.net.URI;
8081
import java.net.URLDecoder;
8182
import java.nio.ByteBuffer;
8283
import java.nio.ByteOrder;
@@ -466,11 +467,18 @@ private void handleIncomingIntent(Intent intent) {
466467
String fileName;
467468

468469
Project externalProject = null;
470+
Uri uri = null;
469471

470-
if(intent.getData() != null && intent.getData().getEncodedPath() != null) {
471-
isOpenByOtherApp = true;
472+
String action = intent.getAction();
473+
String type = intent.getType();
474+
if ( Intent.ACTION_SEND.equals(action) && intent.hasExtra( Intent.EXTRA_STREAM)) {
475+
uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
476+
} else if(intent.getData() != null && intent.getData().getEncodedPath() != null) {
477+
uri = intent.getData();
478+
}
472479

473-
Uri uri = intent.getData();
480+
if ( uri != null) {
481+
isOpenByOtherApp = true;
474482
String encodedPath = uri.getEncodedPath();
475483

476484
String scheme = uri.getScheme();
@@ -479,9 +487,7 @@ private void handleIncomingIntent(Intent intent) {
479487
fileName = fileNameForFlashing(fullPathOfFile);
480488
externalProject = fileName == null ? null : new Project(fileName, fullPathOfFile, 0, null, false);
481489
} else if(scheme.equals("content")) {
482-
483490
Cursor cursor = null;
484-
485491
try {
486492
cursor = getContentResolver().query(uri, null, null, null, null);
487493

@@ -541,7 +547,7 @@ private void handleIncomingIntent(Intent intent) {
541547
if ( mProgramToSend != null) {
542548
startBluetoothForFlashing();
543549
} else {
544-
if (isOpenByOtherApp) {
550+
if ( isOpenByOtherApp) {
545551
Toast.makeText(this, "Not a micro:bit HEX file", Toast.LENGTH_LONG).show();
546552
onFlashComplete();
547553
}

0 commit comments

Comments
 (0)