标签:androidmanifest.xml 版本号 应用名称 meta-data
<?xml version="1.0" encoding="utf-8"?></manifest>
package com.example.android_metadata;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
@SuppressWarnings("deprecation")
public class MainActivity extends ActionBarActivity
{
private TextView tv_data;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_data = (TextView) findViewById(R.id.tv_metadata);
String version = null;
String appName = null;
String appData = null;
String activityData = null;
PackageInfo info;
ApplicationInfo applicationInfo;
ActivityInfo activityInfo;
try
{ // appName、versioName
info = getPackageManager().getPackageInfo(getPackageName(), 0);
appName = info.applicationInfo.loadLabel(getPackageManager()).toString();
version = info.versionName;
// application medadata信息
applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), getPackageManager().GET_META_DATA);
appData = applicationInfo.metaData.getString("app_data");
// activity metadata 信息
activityInfo = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
activityData = activityInfo.metaData.getString("activity_data");
} catch (NameNotFoundException e2)
{
e2.printStackTrace();
}
tv_data.setText("" + appName + "\n" + version + "\n" + appData + "\n" + activityData);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
android 读取 AndroidManifest.xml 中的数据:版本号、应用名称、自定义K-V数据(meta-data)
版权声明:本文为博主原创文章,未经博主允许不得转载。
android 读取 AndroidManifest.xml 中的数据:版本号、应用名称、自定义K-V数据(meta-data)
标签:androidmanifest.xml 版本号 应用名称 meta-data
原文地址:http://blog.csdn.net/ding1145536113/article/details/47079967