• Android之读取 AndroidManifest.xml 中的数据:版本号、应用名称、自定义K-V数据(meta-data)


    AndroidManifest.xml中的定义如下:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="hpc.cai.test01"
    android:versionCode="1"
    android:versionName="1.0" >
    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <meta-data
    android:name="tel"
    android:value="cdma-13366350377" >
    </meta-data>
    <meta-data
    android:name="channel"
    android:value="eben" />
    
    
    <activity
    android:name="hpc.cai.test.Test1Activity"
    android:label="@string/app_name" >
    <meta-data
    android:name="name"
    android:value="自强不息" >
    </meta-data>
    <meta-data
    android:name="city"
    android:value="北京" />
    
    
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    
    
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>
    package net.duohuo.lequ.activity.other;
    
    import android.app.Activity;
    import android.content.pm.ActivityInfo;
    import android.content.pm.ApplicationInfo;
    import android.content.pm.PackageInfo;
    import android.content.pm.PackageManager;
    
    /**
     * Created by ChenZhiNing on 2015/7/30.
     */
    public class MetaDataHelper {
     private Activity mActivity;
    
        public MetaDataHelper(Activity mActivity) {
            this.mActivity = mActivity;
        }
    
        /**
         * activity MetaData读取
         */
        private void testActivityMetaData() {
            ActivityInfo info;
            try {
                info = mActivity.getPackageManager().getActivityInfo(mActivity.getComponentName(), PackageManager.GET_META_DATA);
    
                String msg = info.metaData.getString("name");
                System.out.println("name:" + msg);
    
                msg = info.metaData.getString("city");
                System.out.println("city:" + msg);
    
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * appliction MetaData读取
         */
        private void testApplicationMetaData() {
            ApplicationInfo info;
            try {
                info = mActivity.getPackageManager().getApplicationInfo(mActivity.getPackageName(), PackageManager.GET_META_DATA);
    
                String msg = info.metaData.getString("tel");
                System.out.println("tel:" + msg);
    
                msg = info.metaData.getString("channel");
                System.out.println("channel:" + msg);
    
    
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * 测试版本信息
         */
        private void getVersion() {
            PackageInfo pkg;
            try {
                pkg = mActivity.getPackageManager().getPackageInfo(mActivity.getApplication().getPackageName(), 0);
                String appName = pkg.applicationInfo.loadLabel(mActivity.getPackageManager()).toString();
                String versionName = pkg.versionName;
                System.out.println("appName:" + appName);
                System.out.println("versionName:" + versionName);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    GTK+(基于DirectFB)的字体处理
    控制的字体属性
    [linux手机平台]让应用程序单实例运行
    serif vs sans serif
    关于做事的几点感想
    推荐一部环保电影难以忽视的真相
    短信应用设计备忘录
    手机搜索设计备忘录
    一点概念,
    毕业了,怎么策划的让有意思点呢,
  • 原文地址:https://www.cnblogs.com/niray/p/4688970.html
Copyright © 2020-2023  润新知