Getting resources of another Application

后端 未结 5 1341
别跟我提以往
别跟我提以往 2020-12-03 05:43

Assume I\'ve got 2 Application A and B.

I want to access resources (drawables, images, strings) of an B application from A application. How would I do that?

<
5条回答
  •  情书的邮戳
    2020-12-03 06:23

    For example, let's get the string-array with the ID of entryvalues_font_size from the package com.android.settings

    String[] enries = null;
    try {
        // You can get PackageManager from the Context
        Resources res = getPackageManager().getResourcesForApplication("com.android.settings");
        int resId = res.getIdentifier("entryvalues_font_size", "array", "com.android.settings");
        if (resId != 0) {
            enries = res.getStringArray(resId);
        }
    }
    catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    

提交回复
热议问题