最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
android如何獲取APP的唯一標識applicationId

小編給大家分享一下android如何獲取APP的唯一標識applicationId,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供諸城網(wǎng)站建設、諸城做網(wǎng)站、諸城網(wǎng)站設計、諸城網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、諸城企業(yè)網(wǎng)站模板建站服務,10年諸城做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

使用getIdentifier()方法可以方便的獲各應用包下的指定資源ID。

方式一

int indentify = getResources().getIdentifier(“com.test.demo:drawable/icon”,null,null);

第一個參數(shù)格式是:包名 + : +資源文件夾名 + / +資源名;是這種格式 然后其他的可以為null

方式二

intindentify= getResources().getIdentifier(“icon”, “drawable”, “com.test.demo”);

第一個參數(shù)為ID名,第二個為資源屬性是ID或者是Drawable,第三個為包名。

示例代碼:

import java.lang.reflect.Field;
import android.content.Context;
public class ResourceUtil {
  private static Context sContext;
  public static void init(Context context) {
    if (context != null)
      sContext = context;
  }
  public static int getLayoutId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "layout", sContext.getPackageName());
  }
  public static int getStringId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "string",
        sContext.getPackageName());
  }
  public static int getDrawableId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "drawable", sContext.getPackageName());
  }
  public static int getStyleId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "style",
        sContext.getPackageName());
  }
  public static int getId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "id",
        sContext.getPackageName());
  }
  public static int getColorId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "color", sContext.getPackageName());
  }
  public static int getDimenId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "dimen",
        sContext.getPackageName());
  }
  public static int getAnimId(String paramString) {
    if (sContext == null)
      return 0;
    return sContext.getResources().getIdentifier(paramString, "anim", sContext.getPackageName());
  }
  // 通過反射實現(xiàn)
  public static final int[] getStyleableIntArray(String name) {
    try {
      if (sContext == null)
        return null;
      Field field = Class.forName(sContext.getPackageName() + ".R$styleable").getDeclaredField(name);
      int[] ret = (int[]) field.get(null);
      return ret;
    } catch (Throwable t) {
    }
    return null;
  }
  public static final int getStyleableIntArrayIndex(String name) {
    try {
      if (sContext == null)
        return 0;
      // use reflection to access the resource class
      Field field = Class.forName(sContext.getPackageName() + ".R$styleable").getDeclaredField(name);
      int ret = (Integer) field.get(null);
      return ret;
    } catch (Throwable t) {
    }
    return 0;
  }
}

Android是什么

Android是一種基于Linux內(nèi)核的自由及開放源代碼的操作系統(tǒng),主要使用于移動設備,如智能手機和平板電腦,由美國Google公司和開放手機聯(lián)盟領導及開發(fā)。

看完了這篇文章,相信你對“android如何獲取APP的唯一標識applicationId”有了一定的了解,如果想了解更多相關知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!


網(wǎng)頁題目:android如何獲取APP的唯一標識applicationId
文章路徑:http://fisionsoft.com.cn/article/jpgcso.html