bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

android如何獲取APP的唯一標識applicationId-創新互聯

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

創新互聯專注于企業成都全網營銷、網站重做改版、沁縣網站定制設計、自適應品牌網站建設、H5場景定制商城網站制作、集團公司官網建設、外貿網站建設、高端網站制作、響應式網頁設計等建站業務,價格優惠性價比高,為沁縣等各大城市提供網站開發制作服務。

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

方式一

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

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

方式二

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

第一個參數為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());
  }
  // 通過反射實現
  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內核的自由及開放源代碼的操作系統,主要使用于移動設備,如智能手機和平板電腦,由美國Google公司和開放手機聯盟領導及開發。

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

名稱欄目:android如何獲取APP的唯一標識applicationId-創新互聯
文章起源:http://vcdvsql.cn/article0/ccsioo.html

成都網站建設公司_創新互聯,為您提供小程序開發微信小程序網站制作移動網站建設定制開發網頁設計公司

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

網站建設網站維護公司