[TIMOB-26248] Hyperloop: Android - Cannot use android.provider.MediaStore.Images.Media API
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2020-05-01T20:36:41.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Hyperloop |
| Labels | engReviewed, hyperloop |
| Reporter | Donald Anderson |
| Assignee | Joshua Quick |
| Created | 2018-07-31T11:14:06.000+0000 |
| Updated | 2020-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
| File | Date | Size |
|---|---|---|
| Android MediaStore.Images.Media logs | 2018-07-31T11:13:35.000+0000 | 362871 |
What if you only require
android.provider.MediaStoreand accessImages.Mediafrom the result? e.g.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 alwaysvar MediaStore = require('android.provider.MediaStore'); var DATE_ADDED = MediaStore.Images.Media.DATE_ADDED;MediaStorebeing required, it's sub-constants are accessed via it then.I can't seem to get at the media sub-class. if I use this.
it prints the followingvar mediastore = require('android.provider.MediaStore'); console.log("1:", mediastore.Images); console.log("2:", mediastore.Images.Media);If I use 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: undefinedIt prints this.var Images = require('android.provider.MediaStore.Images'); console.log("1:", Images); console.log("2:", Images.Media);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.[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: undefinedThen it might indeed be a bug. [~jquick] [~gmathews] do you know more?
This appears to be a Hyperloop limitation. The
Mediaclass withinandroid.provider.MediaStore$Images$Mediais an inner class within anotherImagesinner 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'sContentResolverclass instead, which is what theMediaclass 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 theirContentResolverclass documentation can be found here... https://developer.android.com/reference/android/content/ContentResolverThis was resolved as of Titanium 9.0.0 via ticket [TIMOB-27298].