从另一个apk获取资源 [英] Get resources from another apk

查看:367
本文介绍了从另一个apk获取资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一整天都在努力解决这个问题,没有成功。我基本上是试图从另一个apk获取图像资源。



所以如果com.example.app在res文件夹中有一个名为image1.png的图像,我想要com .example2.app能够访问该资源并将其放在imageview中。



我知道你必须使用PackageManager.getResourcesForApplication,但我还是没有成功获得实际资源。



任何帮助都会很棒!

解决方案

想出来...

  final String packName =com.example2.app; 
String mDrawableName =app_icon;

try {
PackageManager manager = getPackageManager();
资源mApk1Resources = manager.getResourcesForApplication(packName);

int mDrawableResID = mApk1Resources.getIdentifier(mDrawableName,drawable,packName);

Drawable myDrawable = mApk1Resources.getDrawable(mDrawableResID);

if(myDrawable!= null)
TEST.setBackgroundDrawable(myDrawable);

}
catch(NameNotFoundException e){
// TODO自动生成的catch块
e.printStackTrace();
}






查看更多说明形成其他问题! 在apk的之间共享原始资源


I have been struggling with this issue all day and have had no success. I am basically trying to get an image resource from another apk.

So if com.example.app has an image called image1.png in the res folder, i want com.example2.app to be able to gain access to that resource and place it in an imageview.

I know you have to use PackageManager.getResourcesForApplication, but i have still been unsuccessful in getting the actual resource.

Any help would be awesome!

解决方案

Figured it out...

final String packName = "com.example2.app";
    String mDrawableName = "app_icon";

    try {
        PackageManager manager = getPackageManager();
        Resources mApk1Resources = manager.getResourcesForApplication(packName);

        int mDrawableResID = mApk1Resources.getIdentifier(mDrawableName, "drawable",packName);

        Drawable myDrawable = mApk1Resources.getDrawable( mDrawableResID );

        if( myDrawable != null )
            TEST.setBackgroundDrawable(myDrawable );

    }
    catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


Check here for more explanation form other question! Share raw resource between apk's

这篇关于从另一个apk获取资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆