Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26248] Hyperloop: Android - Cannot use android.provider.MediaStore.Images.Media API

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2020-05-01T20:36:41.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsHyperloop
LabelsengReviewed, hyperloop
ReporterDonald Anderson
AssigneeJoshua Quick
Created2018-07-31T11:14:06.000+0000
Updated2020-05-01T20:36:41.000+0000

Description

If I create a new project and add
var mediastore = require('android.provider.MediaStore.Images.Media');
I get the following error.
Requested module not found: android.provider.MediaStore.Images.Media
Trace level logs are attached

Attachments

FileDateSize
Android MediaStore.Images.Media logs2018-07-31T11:13:35.000+0000362871

Comments

  1. Hans Knöchel 2018-07-31

    What if you only require android.provider.MediaStore and access Images.Media from the result? e.g.
       var MediaStore = require('android.provider.MediaStore');
       var DATE_ADDED = MediaStore.Images.Media.DATE_ADDED;
       
    Looking [here](https://stackoverflow.com/questions/23343783/how-can-i-fix-errors-about-imports-in-this-code), someone tried your import natively and it did not work either, so you may need to import it like above. It may be because of it's static context, but thats just troubleshooting. In other examples like [here](https://stackoverflow.com/questions/13772138/android-read-any-specific-image-from-sd-card-and-display-it-as-bitmap), it's always MediaStore being required, it's sub-constants are accessed via it then.
  2. Donald Anderson 2018-07-31

    I can't seem to get at the media sub-class. if I use this.
       var mediastore = require('android.provider.MediaStore');
       console.log("1:", mediastore.Images);
       console.log("2:", mediastore.Images.Media);
       
    it prints the following
       [INFO] :   1: function () {
       [INFO] :   var result;
       [INFO] :   // Allow the constructor to either invoke the real java constructor, or function as a "wrapping" method that will take
       [INFO] :   // a single argument that is a native hyperloop proxy for this class type and just wraps it in our JS type.
       [INFO] :   if (arguments.length == 1 && arguments[0].isNativeProxy && arguments[0].isInstanceProxy && arguments[0].isInstanceOf('android.provider.MediaStore$Images')) {
       [INFO] :   result = arguments[0];
       [INFO] :   }
       [INFO] :   else {
       [INFO] :   result = Images.class.newInstance(arguments);
       [INFO] :   }
       [INFO] :   
       [INFO] :   this.$native = result;
       [INFO] :   this._hasPointer = result != null;
       [INFO] :   this._private = {};
       [INFO] :   }
       [INFO] :   2: undefined
       
    If I use this
       var Images = require('android.provider.MediaStore.Images');
       console.log("1:", Images);
       console.log("2:", Images.Media);
       
    It prints this.
       [INFO] :   1: function () {
       [INFO] :   var result;
       [INFO] :   // Allow the constructor to either invoke the real java constructor, or function as a "wrapping" method that will take
       [INFO] :   // a single argument that is a native hyperloop proxy for this class type and just wraps it in our JS type.
       [INFO] :   if (arguments.length == 1 && arguments[0].isNativeProxy && arguments[0].isInstanceProxy && arguments[0].isInstanceOf('android.provider.MediaStore$Images')) {
       [INFO] :   result = arguments[0];
       [INFO] :   }
       [INFO] :   else {
       [INFO] :   result = Images.class.newInstance(arguments);
       [INFO] :   }
       [INFO] :   
       [INFO] :   this.$native = result;
       [INFO] :   this._hasPointer = result != null;
       [INFO] :   this._private = {};
       [INFO] :   }
       [INFO] :   2: undefined
       
    It doesn't seem to matter if I try to import the class directly or access it though it's parents, it doesn't seem to exist.
  3. Hans Knöchel 2018-07-31

    Then it might indeed be a bug. [~jquick] [~gmathews] do you know more?
  4. Joshua Quick 2018-07-31

    This appears to be a Hyperloop limitation. The Media class within android.provider.MediaStore$Images$Media is an inner class within another Images inner class. Hyperloop can access the 1st inner class, but not an inner class within another inner class. I can successfully require it in Hyperloop using the dollar sign '$' version above, but Hyperloop will fail to provide the static constants/methods. So, it doesn't solve anything. You can work-around this issue for now by using Google's ContentResolver class instead, which is what the Media class uses internally. Have a look at Google's code here... [MediaStore.java#L861](https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/provider/MediaStore.java#L861) And their ContentResolver class documentation can be found here... https://developer.android.com/reference/android/content/ContentResolver
  5. Joshua Quick 2020-05-01

    This was resolved as of Titanium 9.0.0 via ticket [TIMOB-27298].

JSON Source