Android 10(Q) 以上普通 APP 隱藏應用圖標問題探究及解決方案

1、實驗環境

aosp 版本 10.0 系統
aosp 版本 13.0 系統

2、驗證結果

2.1 方式一

APP AndroidManifest.xml 中通過 activity-alias 配置帶 LAUNCHER 屬性 category,并且 android:enabled=“true”

10.0 系統中可安裝后正常顯示 icon,通過 setComponentEnabledSetting 隱藏 icon 成功,桌面上不留下 app 相關任何圖標

13.0 系統中可安裝后正常顯示 icon,通過 setComponentEnabledSetting 隱藏 icon 不成功,桌面上會留下透明占位 alias 圖標

2.2 方式二

APP AndroidManifest.xml 中通過 activity-alias 配置帶 LAUNCHER 屬性 category,并且 android:enabled=“false”

10.0 系統中首次安裝后直接不顯示 icon,但通過 setComponentEnabledSetting 可控制隱藏 icon 成功,桌面上不留下 app 相關任何圖標

13.0 系統中首次安裝后直接不顯示 icon,但通過 setComponentEnabledSetting 可控制隱藏 icon 成功,桌面上不留下 app 相關任何圖標

3、展開講講

目前隱藏圖標的思路幾乎都是這樣的,在 AndroidManifest.xml 中配置一些 activity-alias,然后通過

getPackageManager().setComponentEnabledSetting(new ComponentName(con,activityAliasName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,PackageManager.DONT_KILL_APP);

禁用(隱藏) activity-alias 組件

啟用(顯示) activity-alias 組件

在 10.0 以上高版本,谷歌加了補丁更新,導致此種方式不再適用。由這個值 show_hidden_icon_apps_enabled 控制

Settings.Global.putInt(getContentResolver(), “show_hidden_icon_apps_enabled”, 0);

經過驗證,將 show_hidden_icon_apps_enabled 改為 0,高版本上即可延用之前方式隱藏圖標。

但普通app是肯定改不了這個值的,沒有權限 Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

更多解釋可查看

那些年的Android開發經驗記錄
Android應用之隱藏桌面圖標的一種方法
android 動態修改dimens android動態修改圖標和名稱

4、測試代碼

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"package="cn.test.hideicon"><permission android:name="android.permission.WRITE_SECURE_SETTINGS"/><applicationandroid:allowBackup="true"android:icon="@drawable/icon_transparent"android:label="@string/app_name"android:roundIcon="@drawable/ic_cloud"android:supportsRtl="true"android:theme="@style/AppTheme"><!--<activityandroid:name=".MainActivity"android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity>--><activityandroid:name="cn.test.hideicon.AliasMainActivity"android:exported="true"android:theme="@style/KeepLiveTheme"><!-- <intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /><dataandroid:host="MainActivity"android:scheme="com.learn.alias.target"tools:ignore="AppLinkUrlError" /></intent-filter>--><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><category android:name="android.intent.category.TEST" /><category android:name="android.intent.category.LAUNCHER" /><category android:name="com.ksgzlf.djbwrpgk" /><data android:host="goapp.fromchrome" android:scheme="tgsoft" /></intent-filter></activity><!-- 外部要啟動的Activity --><activityandroid:name="cn.test.hideicon.MainActivity"android:excludeFromRecents="true"android:exported="true"android:finishOnTaskLaunch="false"android:launchMode="singleInstance" /><activityandroid:name="cn.test.hideicon.AliasActivity"android:excludeFromRecents="true"android:exported="true"android:finishOnTaskLaunch="false"android:launchMode="singleInstance"android:theme="@style/TransparentStyle"><intent-filter><action android:name="android.intent.action.VIEW" /></intent-filter><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.DEFAULT" /><category android:name="android.intent.category.BROWSABLE" /><category android:name="android.intent.category.TEST" /><category android:name="android.intent.category.LAUNCHER" /><category android:name="com.ksgzlf.djbwrpgk" /><data android:host="goapp.fromchrome" android:scheme="tgsoft" /></intent-filter></activity><activity-aliasandroid:name="cn.test.hideicon.Alias1Activity"android:enabled="true"android:exported="true"android:icon="@drawable/ic_launcher_background"android:label="aaaa"android:launchMode="singleTask"android:roundIcon="@drawable/icon_transparent"android:targetActivity="cn.test.hideicon.MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.DEFAULT" />
<!--                <category android:name="android.intent.category.BROWSABLE" />-->
<!--                <category android:name="android.intent.category.TEST" />--><category android:name="android.intent.category.LAUNCHER" />
<!--                <category android:name="com.ksgzlf.djbwrpgk" />-->
<!--                <data android:host="goapp.fromchrome" android:scheme="tgsoft" />--></intent-filter></activity-alias><activity-aliasandroid:name="com.android.ui.ActivityAliasN"android:configChanges="keyboard|orientation|screenSize"android:enabled="false"android:exported="true"android:icon="@drawable/ic_launcher_background"android:label="bbbb"android:launchMode="singleTask"android:roundIcon="@drawable/icon_transparent"android:targetActivity="cn.test.hideicon.MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity-alias><activity-aliasandroid:name="com.android.ui.ActivityAlias5"android:configChanges="keyboard|orientation|screenSize"android:enabled="true"android:exported="true"android:icon="@drawable/icon_transparent"android:label="maygroup55555"android:launchMode="singleTask"android:roundIcon="@drawable/icon_transparent"android:targetActivity="cn.test.hideicon.MainActivity"><intent-filter tools:ignore="AppLinkUrlError"><action android:name="android.intent.action.CHOOSER" /><action android:name="android.intent.action.MAIN" /><action android:name="android.intent.action.VIEW" /><action android:name="android.intent.action.SEND" /><action android:name="android.intent.action.SEND_MULTIPLE" /><category android:name="android.intent.category.INFO" /><category android:name="android.intent.category.DEFAULT" /><category android:name="com.android.internal.category.PLATLOGO" /><category android:name="android.intent.category.BROWSABLE" /><action android:name="android.intent.action.PACKAGE_REMOVED" /><action android:name="android.intent.action.PACKAGE_REPLACED" /><action android:name="android.intent.action.PACKAGE_ADDED" /><action android:name="android.intent.action.PACKAGE_CHANGED" /><action android:name="com.ui.OnAlarmReceiver.ACTION_WIDGET_RECEIVER" /><action android:name="com.android.vending.billing.InAppBillingService.COIN" /><action android:name="com.android.vending.billing.InAppBillingService.COIO" /><action android:name="com.android.vending.billing.InAppBillingService.LUCM" /><action android:name="com.android.vending.billing.InAppBillingService.PROX" /><action android:name="ir.cafebazaar.pardakht.InAppBillingService.BIND" /><action android:name="ru.aaaaaaax.installer" /><action android:name="com.nokia.payment.iapenabler.InAppBillingService.BIND" /><action android:name="com.android.vending.billing.InAppBillingService.INST" /><action android:name="com.App.Reborn" /></intent-filter></activity-alias></application>
</manifest>

MainActivity.java

public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//adb shell settings get global show_hidden_icon_apps_enabledtry {int showHidden = Settings.Global.getInt(getContentResolver(),"show_hidden_icon_apps_enabled", 1);Log.d("MainActivity", "showHidden: " + showHidden);if (showHidden != 0) {Settings.Global.putInt(getContentResolver(), "show_hidden_icon_apps_enabled", 0);Log.i("MainActivity", "set showHidden: ");}} catch (Exception e) {e.printStackTrace();}}public void show(View view) {String clazzName = "com.android.ui.ActivityAliasN";enableComponent(this, clazzName);enableComponent(this, "cn.test.hideicon.Alias1Activity");finish();}public void hide(View view) {String clazzName = "com.android.ui.ActivityAliasN";disableComponent(this, clazzName);disableComponent(this, "cn.test.hideicon.Alias1Activity");finish();}/*** 啟動組件*/public static void enableComponent(Context context, String clazzName) {ComponentName componentName = new ComponentName(context, clazzName);PackageManager mPackageManager = context.getPackageManager();mPackageManager.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);}/*** 禁用組件*/public static void disableComponent(Context context, String clazzName) {ComponentName componentName = new ComponentName(context, clazzName);PackageManager mPackageManager = context.getPackageManager();mPackageManager.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);}}

AliasMainActivity.java

public class AliasMainActivity extends AppCompatActivity {private Button toActivity, hideActivity;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Window window = getWindow();window.setGravity(Gravity.LEFT | Gravity.TOP);WindowManager.LayoutParams params = window.getAttributes();params.x = 0;params.y = 0;params.width = 1;params.height = 1;window.setAttributes(params);finish();}}

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

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

相關文章

idea中run和debug是灰色的

【現象】idea中run和debug是灰色的 點擊 旁邊的Add Configuration…一看都是空白 【解決方法】&#xff1a; npm點開之后 【結果】

文本轉圖像 學習筆記

VQGAN (Vector Quantized Generative Adversarial Network) 是一種基于 GAN 的生成模型&#xff0c;可以將圖像或文本轉換為高質量的圖像。 VQ &#xff08;Vector Quantization&#xff09;是一種數據壓縮技術&#xff0c;是指將連續數據表示為離散化的向量。輸入的圖像或文本…

轉換NC或HDF數據時候轉出數據無坐標信息的處理方法

有時候我們在轉換NC或HDF數據時&#xff0c;有時候會出現沒有坐標信息的情況&#xff01;如下圖&#xff1a; 這種情況一般是原始數據將坐標信息存儲在說明文件中以便后期做生成坐標信息的處理、或坐標存儲的形式比較特殊&#xff0c;造成工具無法讀取&#xff01;這種數據處理…

Python迭代器與生成器研究記錄

Python迭代器與生成器研究記錄 前言 迭代器肯定是可迭代對象&#xff0c;但是可迭代對象不一定是迭代器&#xff0c;生成器一定是迭代器&#xff0c;但是迭代器不一定是生成器 生成器是特殊的迭代器&#xff0c;所以生成器一定是迭代器&#xff0c;迭代器一定是可迭代對象 我…

YOLOv8分割訓練及分割半自動標注

YOLOv8是基于目標檢測算法YOLOv5的改進版,它在YOLOv5的基礎上進行了優化和改進,加入了一些新的特性和技術,如切片注意力機制、骨干網絡的選擇等。 本文以yolov8-seg為基準,主要整理分割訓練流程及使用v8分割模型進行半自動標注的過程。 一、v8-seg訓練 1.1 環境配置 github…

【Altera】平臺設計器互連會回壓 AXI 接口怎么辦

說明 實現 AXI 接口的所有組件都具有發行或接受能力設置。每當互連檢測到管理器&#xff08;主管理器&#xff09;發出的事務多于管理器的發行容量設置時&#xff0c;互連將通過斷言 AxREADY 向管理器背壓。每當互連檢測到從屬&#xff08;從站&#xff09;接收的事務多于從屬的…

實用篇 | 一文快速構建人工智能前端展示streamlit應用

----------------------- &#x1f388;API 相關直達 &#x1f388;-------------------------- &#x1f680;Gradio: 實用篇 | 關于Gradio快速構建人工智能模型實現界面&#xff0c;你想知道的都在這里-CSDN博客 &#x1f680;Streamlit :實用篇 | 一文快速構建人工智能前端展…

Activity從下往上彈出視差效果實現

其實這篇文章是轉至簡書上的大佬的&#xff0c;加上我自己的代碼實踐了下發現可行&#xff0c;于是就分享下 先看效果 介紹: 其實有很多方法都可以實現這種效果&#xff0c;popwindow&#xff0c;Dialog&#xff0c;BottomSheetDialogFragment&#xff0c;BottomSheetDialog等…

Linux 安裝 Gitea.md

### 從官網下載git 和 gitea Git下載地址: https://mirrors.edge.kernel.org/pub/software/scm/git/ 下載 git-2.43.0.tar.gz: https://mirrors.edge.kernel.org/pub/software/scm/git/git-2.43.0.tar.gz Gitea下載地址: https://dl.gitea.com/gitea/ 下載 linux-arm64 的二進…

鏈表OJ—相交鏈表

提示&#xff1a;文章寫完后&#xff0c;目錄可以自動生成&#xff0c;如何生成可參考右邊的幫助文檔 文章目錄 前言 1、相交鏈表的題目&#xff1a; 方法講解&#xff1a; 圖文解析&#xff1a; 代碼實現&#xff1a; 總結 前言 世上有兩種耀眼的光芒&#xff0c;一種是正在升…

15.Java程序設計-基于SSM框架的微信小程序校園求職系統的設計與實現

摘要&#xff1a; 本研究旨在設計并實現一款基于SSM框架的微信小程序校園求職系統&#xff0c;以提升校園求職流程的效率和便捷性。通過整合微信小程序平臺和SSM框架的優勢&#xff0c;本系統涵蓋了用戶管理、職位發布與搜索、簡歷管理、消息通知等多個功能模塊&#xff0c;為…

愛智EdgerOS之深入解析AI圖像引擎如何實現AI視覺開發

一、前言 AI 視覺是為了讓計算機利用攝像機來替代人眼對目標進行識別&#xff0c;跟蹤并進一步完成一些更加復雜的圖像處理。這一領域的學術研究已經存在了很長時間&#xff0c;但直到 20 世紀 70 年代后期&#xff0c;當計算機的性能提高到足以處理圖片這樣大規模的數據時&am…

ArkUI組件

目錄 一、概述 聲明式UI 應用模型 二、常用組件 1、Image&#xff1a;圖片展示組件 示例 配置控制授權申請 2、Text&#xff1a;文本顯示組件 示例 3、TextInput&#xff1a;文本輸入組件 示例 4、Button&#xff1a;按鈕組件 5、Slider&#xff1a;滑動條組件 …

Swagger PHP Thinkphp 接口文檔

安裝 1. 安裝依賴 composer require zircote/swagger-php 2. 下載Swagger UI git clone https://github.com/swagger-api/swagger-ui.git 3. 復制下載好的Swagger UI 中的dist目錄到public目錄中&#xff0c;修改目錄名稱 cp -rf swagger-ui/dist /home/htdocs/public/ m…

vue中設置滾動條的樣式

在vue項目中&#xff0c;想要設置如下圖中所示滾動條的樣式&#xff0c;可以采用如下方式&#xff1a; ?// 直接寫在vue.app文件中 ::-webkit-scrollbar {width: 3px;height: 3px; } ::-webkit-scrollbar-thumb { //滑塊部分// border-radius: 5px;background-color: #1890ff;…

【智能家居】智能家居項目

智能家居項目目錄 項目目錄結構 完整而典型的項目目錄結構 CMake模板 CMake編譯運行 README.md 項目說明文檔 智能家居項目目錄 【智能家居】面向對象編程OOP和設計模式(工廠模式) 【智能家居】一、工廠模式實現繼電器燈控制 【智能家居】二、添加火災檢測模塊&#xff08;…

4-Docker命令之docker ps

1.docker ps介紹 docker ps命令是用來列出容器的相關信息 2.docker ps用法 docker ps [參數] [rootcentos79 ~]# docker ps --helpUsage: docker ps [OPTIONS]List containersAliases:docker container ls, docker container list, docker container ps, docker psOptions…

【重點】【二叉樹】199.二叉樹的右視圖

題目 法1:層次遍歷 最佳方法&#xff0c;牢記&#xff01;&#xff01;&#xff01; class Solution {public List<Integer> rightSideView(TreeNode root) {List<Integer> res new ArrayList<>();if (root null) {return res;}Queue<TreeNode> q…

Java 克隆:復制構造函數與克隆

為了實現克隆&#xff0c;我們需要配置我們的類并遵循以下步驟&#xff1a; 在我們的類或其超類或接口中實現 Cloneable 接口。 定義一個應處理 CloneNotSupportedException&#xff08;拋出或記錄&#xff09;的 clone() 方法。 并且&#xff0c;在大多數情況下&#xff0c;我…