7777import java .io .InputStream ;
7878import java .io .InputStreamReader ;
7979import java .io .OutputStream ;
80+ import java .net .URI ;
8081import java .net .URLDecoder ;
8182import java .nio .ByteBuffer ;
8283import 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