Java Question onActivityResult: IOnActivityResult was released

warwound

Expert
Licensed User
Longtime User
I have a problem with WebViewExtras and it's WebChromeClient.

With version 1.2 i added a method to enable a user to select a file from their device to upload - if they visited a web page containing a file upload form.
It worked fine.

It now seems to be broken and this log message seems relevant:

onActivityResult: IOnActivityResult was released

IOnActivityResult is being released when the user selects a file.
Then the B4A Activity containing the WebView is resumed and the user chooses to upload the selected file.
Nothing now happens.
The web page file upload form no longer works either - click the button to select a file and nothing happens.
Rotate the device and the Acitivy is blank - the WebView no longer visible.

This log message now appears:

Previously focused view reported id 1 during save, but can't be found during restore.

A similar problem was reported in this post: http://www.b4x.com/forum/basic4android-updates-questions/17540-problem-contentchooser.html.

A-ha i thought...

I made WebViewExtras an Activity Object from version 1.30 as it contained a reference to the BA object.
This was required so an event could be raised when a web page requested to use the device's GPS features.
Versions 1.20 and earlier were NOT Activity Objects.

I loaded the version 1.20 source code, compiled it and tried again - still the same result.

This is on the same device that version 1.20 previously worked on.
The only change i can think of is that i've upgraded to version 1.92 of B4A.

The WebChromeClient openFileChooser method handles the file selection, onGeolocationPermissionsShowPrompt is the method that requires a reference to the BA object:

B4X:
public static final void addWebChromeClient(final BA pBA, final WebView WebView1, final String EventName) {
   WebView1.setWebChromeClient(new WebChromeClient() {

      @Override
      public void onGeolocationPermissionsShowPrompt(String pOrigin, Callback pCallback) {
         //   default does nothing
         //   super.onGeolocationPermissionsShowPrompt(pOrigin, pCallback);
         
         //   Log.d("B4A", "onGeolocationPermissionsShowPrompt");
         
         //   auto allow permission but do not remember
         //   parameters are origin, allow, remember
         
         //   handle permission in B4A
         int permission=(Integer) pBA.raiseEvent(this, EventName.toLowerCase(BA.cul)+"_geolocationpermissionsrequest", new Object[0]);
         
         switch(permission){
            case GEOLOCATION_PERMISSION_ALLOW:{
               pCallback.invoke(pOrigin, true, false);
               break;
            }
            case GEOLOCATION_PERMISSION_ALLOW_AND_REMEMBER:{
               pCallback.invoke(pOrigin, true, true);
               break;
            }
            case GEOLOCATION_PERMISSION_DISALLOW:{
               pCallback.invoke(pOrigin, false, false);
               break;
            }
            case GEOLOCATION_PERMISSION_DISALLOW_AND_REMEMBER:{
               pCallback.invoke(pOrigin, false, true);
            }
         }
      }
      
      // For Android 3.0+
      public void openFileChooser(final ValueCallback<Uri> pUloadMessage, String pAcceptType) {
         Log.d("B4A", "openFileChooser 3.00+");
         Intent i = new Intent(Intent.ACTION_GET_CONTENT);
         i.addCategory(Intent.CATEGORY_OPENABLE);

         i.setType(pAcceptType); //   my code

         IOnActivityResult IOnActivityResult1 = new IOnActivityResult() {
            @Override
            public void ResultArrived(int pResultCode, Intent pIntent) {

               ' these log messages do not appear

               Log.d("B4A", "ResultArrived");
               Log.d("B4A", "pResultCode=" + pResultCode);

               if (pIntent == null) {
                  pUloadMessage.onReceiveValue(null);
               } else {
                  pUloadMessage.onReceiveValue(pIntent.getData());
               }
            }
         };

         pBA.startActivityForResult(IOnActivityResult1, Intent.createChooser(i, "Select a file"));
      }

      // For Android < 3.0
      public void openFileChooser(ValueCallback<Uri> pUploadMessage) {
         Log.d("B4A", "openFileChooser < 3.00");
         openFileChooser(pUploadMessage, "*/*");
      }
   });
}


Anyone got any ideas?

Martin.
 

stefanobusetto

Active Member
Licensed User
Longtime User
hi
i don't think i can be of much help anyway ...
i have an IOnActivityResult working on an activity created in a java library
the difference i see from the code you posted is how the intent is created
i use : "Intent i = new Intent ( ba.context , xnSearch.class ) ;"
 

warwound

Expert
Licensed User
Longtime User
I'm not sure of the technicalities to be honest.

But i think the Intent is to start up the Content Chooser so that's why the Intent is created as it is.
That also ties in with the linked to post reporting the same error.

This did all work when i first wrote it but now fails...

Martin.
 
Top