【转】运行时,获取其它apk的资源方法

http://blog.csdn.net/wen0006/article/details/5797400

package com.cchen.riduritest;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class WTFActivity extends Activity {
	private TextView txt;
	private Resources resources;
	private String packName = "目的包名";
	private ImageView imageView1;
	public static final String AUTHORITY = "com.xxx.packageresources";

	public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY);

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		txt = (TextView) this.findViewById(R.id.txt);
		imageView1 = (ImageView) this.findViewById(R.id.imageView1);


		PackageManager manager = getPackageManager();
	    try {
			resources = manager.getResourcesForApplication(packName);
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    int rid = resources.getIdentifier("wallpaper", "drawable", packName);

		Uri build = CONTENT_URI.buildUpon().appendPath(packName)
				.appendEncodedPath("res").appendPath(String.valueOf(rid)).build();
		txt.setText(build.toString());

		Bitmap b = BitmapFactory.decodeResource(resources, rid, null);
		imageView1.setImageBitmap(b);
	}
}



String[] skinPkgs = getPackageManager().getPackagesForUid(Process.myUid()); 
获取所有同一个  android:sharedUserId="com.hujl.mainskin"  的资源包  ,可以实现多套 skin 的切换 。

你可能感兴趣的:(apk)