[TIMOB-24658] Hyperloop: Android - How to instantiate native Android Drawable?
GitHub Issue | n/a |
---|---|
Type | Story |
Priority | Critical |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2017-09-25T18:55:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Hyperloop |
Labels | android, hyperloop, hyperloop-examples |
Reporter | Jose Zuniga |
Assignee | Gary Mathews |
Created | 2017-05-04T16:24:29.000+0000 |
Updated | 2017-09-25T18:55:12.000+0000 |
Description
*Problem*
I am trying to reference an image file in Hyperloop to instantiate a native Android object (for example, a Drawable).
I am currently using Titanium Hyperloop to create a custom Android class that I wish to port over to my app built on Appcelerator. From the Hyperloop documentation, I can reference the native Android Drawable with:
Drawable = require('android.graphics.drawable.Drawable')
Now, I wish to instantiate a Drawable object through the native Drawable.createFromPath() constructor but my problem is that Titanium is not recognizing the path name to my image in my resources folder in my app directory. For example, the path to my image file is:
{my_app}/assets/images/myImage.png
Any paths I try to pass into the constructor give a "No such file or directory" exception. How do I work with Titanium Hyperloop to construct a native Android Drawable object?
*Test Case*
var Drawable = require('android.graphics.drawable.Drawable');
var imagePath = '/images/myImage.png';
var mImage = Drawable.createFromPath(imagePath);
*Log*
"No such file or directory" exception
*Community Discussion*
[http://stackoverflow.com/questions/43726570/titanium-hyperloop-how-to-instantiate-native-android-drawable]
[~gmathews] I guess the native developer needs to specify a more advanced path to that method right? Since the relative path needs to be mapped to the exact (drawable) directory. [~jzuniga] Maybe only the file name? Or check where the images are copied to in the resulting apk and check the Android docs on how to resolve to that path.
You would need to use the full path, or you could use a stream: