I am trying to support two Icon_Picker intents:
org.adw.launcher.icons.ACTION_PICK_ICON
and
com.betterandroid.launcher2.icons.PICK_ICON_ACTION
Unfortunately ADW, Go Launcher and LauncherPro look for drawables in the /drawable
either using the intent mentioned above, or by using an XML which looks in /drawable
Whereas the old BetterAndroid intent scans for images in the /assets
folder. Now, I know of the great trick for drawables in order to supply a drawable from an XML:
<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/com_aac_cachemate_demo_cachemate" />
</selector>
Therefore instead of supplying a graphic, I point to an existing graphic - Good for not needing duplicate files when referencing the same image, but with different names/ids.
My Questions:
1) Is there any equivalent trick that would work when referencing the /assets
instead of drawable?
2) If I were to use AssetManager
to read the assets and make them drawables:
a) Would they be readable by the Intent scanning for those drawables?
b) Would the app size inevitably double in size anyway?
c) How would I implement AssetManager correctly for this to work? Something like:
sampleimage= BitmapFactory.decodeResource(context.getResources(), R.drawable.sampleimage);
maybe? Or would there be better options to getAsset()
from an Array maybe?
What I'm trying to achieve is not only have the images in /drawable
but also somehow linked to /assets
so that both intents can scan and find the drawables and display in their gridview without having to duplicate the graphics (putting them in both assets and drawable folders. Thanks for any help!
EDIT: android: how to load xml file from assets directory? was a very helpful read, but I'm not sure it completely rules out what I'm trying to achieve. Any/All input is appreciated.
So: It seems I would have to do it the other way, if it is to work at all. (The other way) meaning I need to store the graphics in the assets
folder and then use AssetManager
to get them into drawable
. Any suggestions on how to do that? Is there no way to reference the assets by using XML in the drawable
folder?
Therefore the questions that really matter to me, If I were to use AssetManager
to read the assets and make them drawables:
1) Would they be readable by the Intent scanning for those drawables?
2) Would the app size inevitably double in size anyway?
In your Android/Java source code you can also refer to that same image like this: Resources res = getResources(); Drawable drawable = res. getDrawable(R.
Drawable drawable = ResourcesCompat. getDrawable (res, R. drawable. myimage, null);
Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure. Step 3: Then a pop-up screen will arise like below. Here choose your directory where you want to store your image file. And click on OK.
You can use the new Resource Manager tab Click on the + sign and select Import Drawables . From here, you can select multiple folders/files and it will handle everything for you. Click the import button and the images will be automatically imported to the correct folder.
Is there any equivalent trick that would work when referencing the /assets instead of drawable?
No, sorry.
If I were to use AssetManager to read the assets and make them drawables
I am going to interpret this as meaning creating Drawable
Java objects.
a) Would they be readable by the Intent scanning for those drawables?
Intent
s do not "scan for drawables" any more than pieces of paper write letters or bullets shoot people. Hence, I have no idea what you are talking about. Moreover, I suspect that the only people who could answer that question are the developers of the two third-party apps you are interested in. Heck, neither of those two Intent
actions seem documented -- this is the one and only page on the entire Internet that seems to mention com.betterandroid.launcher2.icons.PICK_ICON_ACTION
, based upon a Google search -- so it is entirely possible the authors of those apps are not looking for you to be doing what you are trying to do.
b) Would the app size inevitably double in size anyway?
If by "size" you mean "size on disk", then no, reading things at runtime does not increase disk space.
c) How would I implement AssetManager correctly for this to work?
Call open()
on AssetManager
to get an InputStream
on your image, then pass that to BitmapFactory.decodeStream()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With