Example usage for android.content.res Resources getResourceName

List of usage examples for android.content.res Resources getResourceName

Introduction

In this page you can find the example usage for android.content.res Resources getResourceName.

Prototype

public String getResourceName(@AnyRes int resid) throws NotFoundException 

Source Link

Document

Return the full name for a given resource identifier.

Usage

From source file:Main.java

public static boolean isExists(Resources resources, int resid) {
    try {/*from www .  ja v  a2  s  .com*/
        resources.getResourceName(resid);
    } catch (NotFoundException e) {
        return false;
    }
    return true;
}

From source file:com.avapira.bobroreader.Bober.java

public static String rawJsonToString(Resources res, @RawRes int resId) {
    String name = res.getResourceName(resId);
    BufferedInputStream bis = new BufferedInputStream(res.openRawResource(resId));
    try {//from   w  w  w .j a va 2 s.  c  o  m
        byte[] bytes = new byte[bis.available()];
        int bytesRead = bis.read(bytes);
        Log.i("Bober#rawJsonToString", String.format("Streaming raw file %s: %s bytes read", name, bytesRead));
        return new String(bytes);
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    }
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

String getResourceName(PackageInfo packInfo, int resId) throws PackageManager.NameNotFoundException {
    String resName = "";
    if (resId != 0) {
        AssetManager assetMgr = this.getActivity().createPackageContext(packInfo.packageName, 0).getAssets();
        try {// w w w. j  av a  2s.  co m
            Resources res;
            Configuration config = new Configuration();
            DisplayMetrics metrics = Utils.getDisplayMetrics(GlobalInfo.s_globalInfo.mainFragActivity);

            res = new Resources(assetMgr, metrics, config);
            resName = res.getResourceName(resId);
            if (resName.length() > 30)
                resName = resName.substring(resName.length() - 30);
            // String resName = res.getText(resId).toString();
        } finally {
            // res.getAssets().close();
            // assetMgr.close();
        }
    }
    return resName;
}