zoukankan      html  css  js  c++  java
  • Android 开发工具类 01_AppUtils

    1、获取应用程序名称;

    2、获取应用程序版本信息。

     1 import android.content.Context;
     2 import android.content.pm.PackageInfo;
     3 import android.content.pm.PackageManager;
     4 import android.content.pm.PackageManager.NameNotFoundException;
     5 
     6 // 跟 App 相关的辅助类
     7 public class AppUtils
     8 {
     9 
    10     private AppUtils()
    11     {
    12         /* cannot be instantiated */
    13         throw new UnsupportedOperationException("cannot be instantiated");
    14 
    15     }
    16 
    17     /**
    18      * 获取应用程序名称
    19      */
    20     public static String getAppName(Context context)
    21     {
    22         try
    23         {
    24             PackageManager packageManager = context.getPackageManager();
    25             PackageInfo packageInfo = packageManager.getPackageInfo(
    26                     context.getPackageName(), 0);
    27             int labelRes = packageInfo.applicationInfo.labelRes;
    28             return context.getResources().getString(labelRes);
    29         } catch (NameNotFoundException e)
    30         {
    31             e.printStackTrace();
    32         }
    33         return null;
    34     }
    35 
    36     /**
    37      * [获取应用程序版本名称信息]
    38      * 
    39      * @param context
    40      * @return 当前应用的版本名称
    41      */
    42     public static String getVersionName(Context context)
    43     {
    44         try
    45         {
    46             PackageManager packageManager = context.getPackageManager();
    47             PackageInfo packageInfo = packageManager.getPackageInfo(
    48                     context.getPackageName(), 0);
    49             return packageInfo.versionName;
    50 
    51         } catch (NameNotFoundException e)
    52         {
    53             e.printStackTrace();
    54         }
    55         return null;
    56     }
    57 
    58 }
  • 相关阅读:
    Pymongo
    asp.net mvc4 使用java异步提交form表单时出现[object object] has no method ajaxSubmit
    C# Activator.CreateInstance()
    GridView中某一列值的总和(web)
    02.[WPF]如何固定窗口的大小
    01.WPF中制作无边框窗体
    C#.net时间戳转换
    org.springframework.beans.factory.BeanCreationException: 求教育!
    log4Net配置详解
    SQL语句-创建索引
  • 原文地址:https://www.cnblogs.com/renzimu/p/4535612.html
Copyright © 2011-2022 走看看