Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to Accessing Resources and Resource Ids of other Apps

After some research and practice, I have observed that we can access Resources of other Apps using PackageManager like

Resources resources = getApplicationContext().getPackageManager().getResourcesForApplication(appPackageName);

but merely accessing Resources is not sufficient. We need Ids for every Resource component like Drawables, layouts,Strings etc etc... to access them from Resources.

I have searched in SO and struggled a lot myself about how to get Resource Ids of other Apps but didn't get proper solution. I have seen in SO, some people suggested to use methods like

resources.getIdentifier(String name, String defType, String defPackage);
resources.getValue(String name, TypedValue outValue, boolean resolveRefs);
resources.getValue(int id, TypedValue outValue, boolean resolveRefs);

but don't have Idea how to use them.

I need to access Resources(Drawables, Strings, Layouts...) of other Apps.

Help me in this concern. Any help would be greatly appreciated...

thank you all and sorry for my english...

like image 879
RuntimeException Avatar asked Nov 23 '22 09:11

RuntimeException


1 Answers

Thanks for your question, I can able to access via following code. It is working fine..

String lAppPkg = "com.example.sharedlogos";
resources = getApplicationContext().getPackageManager()
                            .getResourcesForApplication(lAppPkg);
int lID = resources.getIdentifier( mID, "drawable",
                            lAppPkg);
mImage.setBackground(resources.getDrawable(lID));
like image 117
Muthuraj Avatar answered Mar 08 '23 23:03

Muthuraj