Android 读取<meta-data>元素的数据
来源:互联网 发布:pcb电路板设计软件 编辑:程序博客网 时间:2024/05/17 06:59
Android 读取<meta-data>元素的数据
在AndroidManifest.xml中,<meta-data>元素可以作为子元素,被包含在<activity>、<application> 、<service>和<receiver>元素中,但不同的父元素,在应用时读取的方法也不同。
1 :在Activity的应用。
xml代码段:
<activity...>
<meta-data android:name="myMsg" android:value="hello my activity"></meta-data>
</activity>
java代码段:
ActivityInfo info=
this
.getPackageManager().getActivityInfo(getComponentName(),PackageManager.GET_META_DATA);
String msg=info.metaData.getString(
"myMsg"
);
System.out.println(
"myMsg:"
+msg);
2:在application的应用。
xml代码段:
<application...>
<meta-data android:value="hello my application" android:name="myMsg"></meta-data>
</application>
java代码段:
ApplicationInfo appInfo =
this
.getPackageManager().getApplicationInfo(getPackageName(),PackageManager.GET_META_DATA);
String msg=appInfo.metaData.getString(
"myMsg"
);
System.out.println(
"myMsg:"
+msg);
3:在service的应用。
xml代码段:
<service android:name="MetaDataService">
<meta-data android:value="hello my service" android:name="myMsg"></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(
"myMsg"
);
System.out.println(
"myMsg:"
+msg);
4: 在receiver的应用。
xml代码段:
<receiver android:name="MetaDataReceiver">
<meta-data android:value="hello my receiver" android:name="myMsg"></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(
"myMsg"
);
System.out.println(
"myMsg:"
+msg);
以上例子在android2.1运行通过
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- Android读取meta-data元素的数据
- Android 读取<meta-data>元素的数据
- Android 读取<meta-data>元素的数据
- 关于Cookie跨域的问题
- 创建任务需要大量的图形和设计和生产工作
- c# 自定义事件和委托
- 如何编写出高效的数据库连接池(附带完整代码C#和Java实现) .
- SqlCommandBuilder 的使用
- Android 读取<meta-data>元素的数据
- Leetcode:Combination Sum II
- 自悟
- SVM入门(一)至(三)Refresh
- rtsp协议总结
- How to write the better Makefile for cpputest
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
- Android StagFright架构分析
- UITableView 的head 右边提示关键字母