Search code examples
androidappcelerator-mobiletitanium-modules

Assets folder in Titanium


I wrote a module that creates a cameraview overlayed with an imageView to shoot the photo, my problem is that since i can't pass the image in the "res" folder i need to place it in "assets", in pure java it all works fine, but i heaven't understood where to place "assets" file in the titanium project once i exported the module. And it crashes when i call the method with an IOException. Thanks

    FrameLayout fl = new FrameLayout(this);
    SurfaceView preview = new SurfaceView(this);
    ImageView footerCam = new ImageView(this);
    LinearLayout ll = new LinearLayout(this);

    LinearLayout.LayoutParams shareParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    footerCam.setLayoutParams(shareParams);
    ll.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);

    ll.addView(footerCam);
    fl.addView(preview);
    fl.addView(ll);

    setContentView(fl);
    camera = Camera.open();

    try 
    {
     AssetManager am = getAssets();
     BufferedInputStream buf = new BufferedInputStream(am.open("footer1.png"));
     Bitmap bitmap = BitmapFactory.decodeStream(buf);
     footerCam.setImageBitmap(bitmap);
     buf.close();
   }   
   catch (IOException e) 
   {
       Log.e("IMG","@@@@@@@@@@@@@@@@@@@@@@@ ERROR LOADING IMAGE");
       e.printStackTrace();
   }

this is the piece of code where i declare the button and assign it an image from the assets folder, but works only in android, when i deploy the module and include it in titanium it falls in IOException, where do i need to place the file "footer1.png" or the "assets" folder?


Solution

  • I managed it with this sort of worksround

    int resID = getResources().getIdentifier("IMG.png", "drawable", "it.temp");
    // or
    int resID = getResources().getIdentifier("it.temp:drawable/icon",null,null);
    
    button.setBackgroundResource(resID);// or whatever you need
    

    but you have to put the image in the same package as the sourcecode.