meta-data获取小结

简介: android 开发中:   在AndroidManifest.xml中,元素可以作为子元素,   被包含在、 、和元素中, 不同的父元素,在应用时读取的方法也不同。   1 :在Activity应用元素。

android 开发中:

 
在AndroidManifest.xml中,<meta-data>元素可以作为子元素,
 
被包含在<activity>、<application> 、<service>和<receiver>元素中,
不同的父元素,在应用时读取的方法也不同。
 
1 :在Activity应用<meta-data>元素。
    xml代码段:
   <activity...>
       <meta-data android:name="meta_data_Name" android:value="hello my activity"></meta-data>
    </activity>
  
    java代码段:
   ActivityInfo info=this.getPackageManager()
                          .getActivityInfo(getComponentName(),
                          PackageManager.GET_META_DATA);
    String msg =info.metaData.getString("meta_data_Name");
    Log.d(TAG, " msg == " + msg );
 
2:在application应用<meta-data>元素。
   xml代码段:
  <application...>
       <meta-data android:value="hello my application" android:name="meta_data_Name"></meta-data>
   </application>
 
   java代码段:
    ApplicationInfo appInfo = this.getPackageManager()
                                  .getApplicationInfo(getPackageName(),
                          PackageManager.GET_META_DATA);
    String msg=appInfo.metaData.getString("meta_data_Name");
    Log.d(TAG, " msg == " + msg );
 
3:在service应用<meta-data>元素。
   xml代码段:
   <service android:name="MetaDataService">
      <meta-data android:value="hello my service" android:name="meta_data_Name"></meta-data>
   </service>
 
   java代码段:
   ComponentName cn=new ComponentName(this, MetaDataService.class);
   ServiceInfo info=this.getPackageManager()
                        .getServiceInfo(cn, PackageManager.GET_META_DATA);
    String msg=info.metaData.getString("meta_data_Name");
    Log.d(TAG, " msg == " + msg );
 
4: 在receiver应用<meta-data>元素。
   xml代码段:
    <receiver android:name="MetaDataReceiver">
            <meta-data android:value="hello my receiver" android:name="meta_data_Name"></meta-data>
            <intent-filter>
                <action android:name="android.intent.action.PHONE_STATE"></action>
            </intent-filter>
    </receiver>
   java代码段:
    ComponentName cn=new ComponentName(context, MetaDataReceiver.class);
    ActivityInfo info=context.getPackageManager()
                             .getReceiverInfo(cn, PackageManager.GET_META_DATA);
    String msg=info.metaData.getString("meta_data_Name");
  
目录
相关文章
|
8月前
|
XML JSON 人工智能
Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
Error while extracting response for type [class xxx] and content type application/xml;charset=UTF-8
491 0
|
4月前
|
XML 数据格式
restTemplat发post请求报错Content type ‘application/xml;charset=UTF-8‘ not supported“
restTemplat发post请求报错Content type ‘application/xml;charset=UTF-8‘ not supported“
|
5月前
head 插件 Content-Type header [application/x-www-form-urlencoded] is not supported
head 插件 Content-Type header [application/x-www-form-urlencoded] is not supported
42 1
|
6月前
|
JSON 数据格式
Content type ‘multipart/form-data;boundary=------57031299820747271;charset=UTF-8‘ not supported的解决方案
Content type ‘multipart/form-data;boundary=------57031299820747271;charset=UTF-8‘ not supported的解决方案
60 0
|
9月前
|
JSON Java 数据格式
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
HttpMediaTypeNotSupportedException: Content type ‘application.yml/json;charset=UTF-8‘ not supported
152 0
|
XML JSON 前端开发
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
讲述ajax请求后端传参报 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported问题处理
 Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
|
前端开发 Windows
【BootStrap】<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 的说明
【BootStrap】<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 的说明
188 0
【BootStrap】<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 的说明
|
索引 机器人 缓存
meta的使用
简体中文: 繁体中文: 英 语:  网页制作者信息 网站简介   搜索关键字     禁止浏览器从本地机的缓存中调阅页面内容。
1114 0
|
移动开发 编解码 Android开发
HTML5 meta viewport参数详解
随着移动端的流行,在移动端对网站进行重构和开发势在必行。但是你只有了解了移动设备的meta viewport参数之后,才能更好地让我们的网页适配或响应各种不同分辨率的移动设备。
1269 0
|
缓存 搜索推荐 Java