8.Android(通過Manifest配置文件傳遞數據(meta-data))

?

配置文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><applicationandroid:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.MyApplication"tools:targetApi="31"><!--   1.application標簽下是全局元元素--><meta-dataandroid:name="api_kay"android:value="123dad*^t8"/><activityandroid:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><!--2.activity局部元元素--><meta-dataandroid:name="LiLi"android:value="hello"/></activity></application></manifest>

活動

package com.example.myapplication;import static android.content.ContentValues.TAG;import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;import java.text.BreakIterator;public class MainActivity extends AppCompatActivity implements View.OnClickListener {@SuppressLint("MissingInflatedId")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);EdgeToEdge.enable(this);setContentView(R.layout.activity_main);findViewById(R.id.activity_btn).setOnClickListener(this);findViewById(R.id.application_btn).setOnClickListener(this);ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);return insets;});}@Overridepublic void onClick(View v) {TextView text = findViewById(R.id.get_api);if(v.getId() == R.id.application_btn){//        1.全局元數據的獲取方式try {ApplicationInfo info = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);String api_kay = info.metaData.getString("api_kay");Log.d(TAG, "_________________" + api_kay);// 使用配置值(如顯示到TextView)text.setText(api_kay);} catch (PackageManager.NameNotFoundException e) {throw new RuntimeException(e);}}if(v.getId() == R.id.activity_btn){//        2.局部元數據的獲取方式try {ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);String LiLi = info.metaData.getString("LiLi");Log.d(TAG, "_________________" + LiLi);// 使用配置值(如顯示到TextView)text.setText(LiLi);} catch (PackageManager.NameNotFoundException e) {throw new RuntimeException(e);}}}
}

布局

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:id="@+id/main"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><TextViewandroid:id="@+id/get_api"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><Buttonandroid:id="@+id/activity_btn"android:layout_width="match_parent"android:layout_height="50dp"android:text="點擊獲取局部元數據"tools:ignore="MissingConstraints" /><Buttonandroid:id="@+id/application_btn"android:layout_width="match_parent"android:layout_height="50dp"android:text="點擊獲取全局元數據"tools:ignore="MissingConstraints" />
</LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/78903.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/78903.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/78903.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java 解析入參里的cron表達式,修改周時間

文章目錄 前言一、java 解析入參里的cron表達式,修改周時間二、使用步驟1.示例 總結 前言 一、java 解析入參里的cron表達式,修改周時間 示例&#xff1a; 第一種: 0 0 0,16 ? * 0,1 第2種 0 0 0,16 ? * 1-7 第3種 0 0 0,16 ? * ? 第4種 0 0 0,16 ? * * 二、使用步驟 1…

DTO,VO,PO,Entity

1. DTO (Data Transfer Object) 定義 DTO 是數據傳輸對象&#xff0c;用于在不同系統或層之間傳輸數據。 目的 簡化數據傳輸&#xff0c;降低耦合&#xff0c;通常只包含需要傳輸的字段&#xff0c;避免暴露內部實現細節。 使用場景 Controller 和 Service 或 遠程調用 之…

從零搭建高可用分布式限流組件:設計模式與Redis令牌桶實踐

一、需求背景與設計目標 在分布式系統中&#xff0c;面對突發流量時需要一種精準可控的流量控制手段。我們的組件需要具備&#xff1a; 多維度限流&#xff08;用戶/IP/服務節點/自定義表達式&#xff09;分布式環境下精準控制開箱即用的Spring Boot Starter集成高擴展性的架…

Node.js 事件循環和線程池任務完整指南?

在 Node.js 的運行體系中&#xff0c;事件循環和線程池是保障其高效異步處理能力的核心組件。事件循環負責調度各類異步任務的執行順序&#xff0c;而線程池則承擔著處理 CPU 密集型及部分特定 I/O 任務的工作。接下來&#xff0c;我們將結合圖示&#xff0c;詳細剖析兩者的工作…

echarts自定義圖表--儀表盤

基于儀表盤類型的自定義表盤 上圖為3層結構組成 正常一個儀表盤配置要在外圈和內圈之間制造一條縫隙間隔 再創建一個儀表盤配置 背景透明 進度條拉滿 進度條顏色和數據的背景相同開始處的線 又一個儀表盤配置 數值固定一個比較小的值 <!DOCTYPE html> <html><h…

【數據結構】圖論存儲結構深度解析:鄰接多重表如何實現無向圖O(1)刪邊?鄰接矩陣/鏈表/十字鏈對比

鄰接多重表 導讀一、有向圖的存儲結構二、鄰接多重表三、存儲結構四、算法評價4.1 時間復雜度4.2 空間復雜度 五、四種存儲方式的總結5.1 空間復雜度5.2 找相鄰邊5.3 刪除邊或結點5.4 適用于5.5 表示方式 六、圖的基本操作結語 導讀 大家好&#xff0c;很高興又和大家見面啦&a…

【Rust】所有權

目錄 所有權基本概念所有權介紹棧與堆變量作用域 字符串字符串字面值&#xff08;&str&#xff09;String 類型相互轉換所有權 內存結構對比注意事項和常見坑使用場景 內存與分配變量與數據交互的方式&#xff08;一&#xff09;&#xff1a;移動變量與數據交互的方式&…

4月29日日記

終于是考完解析幾何了&#xff0c;今天昨天突擊了一下&#xff0c;感覺確實學會了很多之前不會的東西&#xff0c;但是可能距離高分還差很多。這次考試不太理想。大部分原因是前期沒學&#xff0c;吸取教訓&#xff0c;早點開始復習微積分。明天還有一節微積分&#xff0c;但是…

【深度對比】Google Play與IOS 馬甲包處理差異分析

在移動應用發布與推廣過程中&#xff0c;馬甲包&#xff08;Cloned App / Alternate Version&#xff09; 曾被廣泛用于流量測試、風險隔離、多品牌運營等場景中。隨著 Google Play 與 Apple App Store 審核政策不斷收緊&#xff0c;開發者們越來越關注兩個平臺對“馬甲包”的態…

MCP 架構全解析:Host、Client 與 Server 的協同機制

目錄 &#x1f3d7;? MCP 架構全解析&#xff1a;Host、Client 與 Server 的協同機制 &#x1f4cc; 引言 &#x1f9e9; 核心架構組件 1. Host&#xff08;主機&#xff09; 2. Client&#xff08;客戶端&#xff09; 3. Server&#xff08;服務器&#xff09; &#…

記錄一次無界微前端的簡單使用

記錄一次無界微前端使用 無界微前端主應用子應用nginx配置 無界微前端 https://wujie-micro.github.io/doc/ 因為使用的是vue項目主應用和次應用都是 所以用的封裝的。 https://wujie-micro.github.io/doc/pack/ 主應用 安裝 選擇對應的版本 # vue2 框架 npm i wujie-vue2…

LLM應用于自動駕駛方向相關論文整理(大模型在自動駕駛方向的相關研究)

1、《HILM-D: Towards High-Resolution Understanding in Multimodal Large Language Models for Autonomous Driving》 2023年9月發表的大模型做自動駕駛的論文&#xff0c;來自香港科技大學和人華為諾亞實驗室&#xff08;代碼開源&#xff09;。 論文簡介&#xff1a; 本文…

FTP-網絡文件服務器

部署思路 單純上傳下載ftp系統集成間的共享 samba網絡存儲服務器 NFS 網絡文件服務器&#xff1a;通過網絡共享文件或文件夾&#xff0c;實現數據共享 NAS &#xff08; network append storage):共享的是文件夾 FTP&#xff1a;文件服務器samba&#xff1a;不同系統間的文件…

在 Ubuntu 22.04 x64 系統安裝/卸載 1Panel 面板

一、 1Panel 是什么&#xff1f; 1Panel 是一款基于 Go 語言開發的現代化開源服務器管理面板&#xff08;類似寶塔面板&#xff09;&#xff0c;專注于容器化&#xff08;Docker&#xff09;和云原生環境管理&#xff0c;提供可視化界面簡化服務器運維操作。 1. 1Panel主要功…

Redis | Redis集群模式技術原理介紹

關注&#xff1a;CodingTechWork Redis 集群模式概述 Redis 集群&#xff08;Cluster&#xff09;模式是 Redis 官方提供的分布式解決方案&#xff0c;旨在解決單機 Redis 在數據量和性能上的限制。它通過數據分片、高可用性和自動故障轉移等特性&#xff0c;提供了水平擴展和…

Servlet小結

視頻鏈接&#xff1a;黑馬servlet視頻全套視頻教程&#xff0c;快速入門servlet原理servlet實戰 什么是Servlet&#xff1f; 菜鳥教程&#xff1a;Java Servlet servlet&#xff1a; server applet Servlet是一個運行在Web服務器&#xff08;如Tomcat、Jetty&#xff09;或應用…

數據庫進階之MySQL 程序

1.目標 1> 了解mysqlId服務端程序 2> 掌握mysql客戶端程序的使用 3> 了解工具包中的其他程序 2. MySQL程序簡介 本章介紹 MySQL 命令?程序以及在運?這些程序時指定選項的?般語法(如:mysql -uroot -p)。 對常?程序進?詳細的講解(實用工具的使用方法)&#xf…

VS2022 設置 Qt Project Settings方法

本文解決的問題&#xff1a;創建完成后&#xff0c;如需要用到Sql或者Socket等技術&#xff0c;需要設置Qt Project Settings&#xff1b; 1、打開VS2022編譯器&#xff0c;創建QT項目工程 2、創建完成后&#xff0c;點擊 解決方案 →右鍵屬性 3、選擇 Qt Project Settings →…

React:封裝一個評論回復組件

分析 用戶想要一個能夠顯示評論列表&#xff0c;并且允許用戶進行回復的組件。可能還需要支持多級回復&#xff0c;也就是對回復進行再回復。然后&#xff0c;我要考慮組件的結構和功能。 首先&#xff0c;數據結構方面&#xff0c;評論應該包含id、內容、作者、時間&#xf…

wx讀書某sign算法詳解

未加固 版本&#xff1a;9.2.3 前置知識&#xff1a; (v41 & 0xFFFFFFFFFFFFFFFELL) 是一種高效的奇偶檢查方法&#xff0c;用于判斷數值 v41 是否為奇數。 std::sort<std::lessstd::string,std::string &,std::string>(a1, v6, s); 排序算法 # 完全等價的字…