ACTION_GET_CONTENT / ACTION_OPEN_DOCUMENT to open ASD? (WebViewExtra)

You should use ADB to know the exact spot of the error.

I should :wink:

I will go and find a cable. :wink:

Or just do it wireless :grin: If you are on the same wifi.

Developer Options -> Wireless Debugging
First time, do pairing using adb pair <ip> (you'll be prompted to enter pair code)
Then normally connect using adb connect <ip>, and to list connected devices do adb devices

(or send me the APK)

2 Likes

Looks like it is not capturing the listpicker intent output

logcat
04-10 11:18:07.663 30292 30292 I Form    : Form Screen1 got onActivityResult, requestCode = 4, resultCode = -1
04-10 11:18:07.664 30292 30292 D AndroidRuntime: Shutting down VM
04-10 11:18:07.665 30292 30292 E AndroidRuntime: FATAL EXCEPTION: main
04-10 11:18:07.665 30292 30292 E AndroidRuntime: Process: edu.mit.appinventor.aicompanion3, PID: 30292
04-10 11:18:07.665 30292 30292 E AndroidRuntime: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=4, result=-1, data=Intent { (has extras) }} to activity {edu.mit.appinventor.aicompanion3/edu.mit.appinventor.aicompanion3.Screen1}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5338)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5377)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:106)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:201)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:288)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7918)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at uk.co.metricrat.webviewextra.WebViewExtra.getFileName(WebViewExtra.java:203)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at uk.co.metricrat.webviewextra.WebViewExtra.resultReturned(WebViewExtra.java:194)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at com.google.appinventor.components.runtime.Form.onActivityResult(Form.java:588)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.Activity.dispatchActivityResult(Activity.java:8665)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5331)
04-10 11:18:07.665 30292 30292 E AndroidRuntime: 	... 13 more
04-10 11:18:07.672  1759 31838 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
04-10 11:18:07.673  1759 11200 W ActivityTaskManager:   Force finishing activity edu.mit.appinventor.aicompanion3/.Screen1
04-10 11:18:07.691 30292 30292 I Process : Sending signal. PID: 30292 SIG: 9
04-10 11:18:07.691  1759  1995 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver
04-10 11:18:07.691  1759  1995 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
04-10 11:18:07.730  1759 11200 D AutofillSession: handling death of Token{7a7c32b ActivityRecord{e276388 u0 edu.mit.appinventor.aicompanion3/.Screen1} t2090 f}}} when saving=false
04-10 11:18:07.731  1258  1258 I Zygote  : Process 30292 exited due to signal 9 (Killed)
04-10 11:18:07.731  1759 11590 I ActivityManager: Process edu.mit.appinventor.aicompanion3 (pid 30292) has died: prcp TOP 

Check your class WebViewExtra and the method named getFileName, there's where the error is appearing from.

First need to check the value of dataString ?

      if (uploadDirectory) {
        dataString = data.getStringExtra("com.google.appinventor.components.runtime.ListPickerActivity.selection");
      } else {
        dataString = data.getDataString();
      }

How can I "print" the value of dataString to logcat ? I can then compare both types to hopefully see why the getFileName method doesn't like the content?

This ?
Log.d("TAG","Value: " + dataString);

1 Like

OK, when using the Shared Directories, it is returning a content uri, like so:

TAG : Value: content://com.android.externalstorage.documents/document/primary%3ADocuments%2FSharedASD%2Fai2metricrat.png

When using the listpicker, I get back:

D TAG : Value: /storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/greenSquare.png
which is what I currently have in the listpicker (selection)

Am thinking the "easiest" thing to do is get the content uri path for the ASD, reduce the listpicker to just filenames (no paths), then add the content uri path to the filename.

or just convert the dataString to a content uri ? (trying to find code for that)

This seems like it would be the most user-friendly. Do people care to know that the file they are picking happens to be located in /storage/emulated/...? This would be the same for every file and so it doesn't provide much useful information (versus "greenSquare.png")

I believe we have solved this :slight_smile:

I successfully upload a file to my server using the listpicker as a selector of files from the ASD

Once I set the file path to a full path (starts with file://), and converted the file path to a content uri with this code:

  Uri uri = Uri.parse(data.getStringExtra("com.google.appinventor.components.runtime.ListPickerActivity.selection"));
  dataString = String.valueOf(uri);

it all started working :tada:

I have some tidying up to do now, and need to generate a list of all files from all sub-directories (I have a procedure that does this)

It is not perfect, there is quite a bit going on in the blocks to make this work, but for now, we can mark this as success.

Thank you @ewpatton and @Kumaraswamy for your invaluable help and encouragement.

A new version of webviewextra with full instructions will be released in due course.

1 Like

Of course I have come to realise, that with the correct settings, it is possible to use the lispicker method for just about any accessible folder :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.