Android——metaData

时间:2024-10-30 08:50:04
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_meta_data); TextView tv_meta = findViewById(R.id.tv_meta); //获取应用包管理 PackageManager packageManager = getPackageManager(); try { //从应用包管理器中获取当前的活动信息 ActivityInfo info = packageManager.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA); //获取活动附加的元数据信息 Bundle bundle = info.metaData; String weather = bundle.getString("weather"); tv_meta.setText(weather); } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException(e); } }