关于MIUI悬浮窗权限问题的解决方案的一点补充

本文提供了解决MIUI悬浮窗权限问题的方案,并通过试错法找到了关键权限android.permission.SYSTEM_ALERT_WINDOW,同时探讨了华为、锤子等设备类似问题的解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     本文是对《关于MIUI悬浮窗权限问题的解决方案》的一点补充,首先感谢大神的分享。

     使用大神的方案实现了对V5版本的悬浮窗设置,但V6版本的悬浮窗设置没有展示出来。首先想到是不是MIUI有什么特殊的权限,所以才导致无法展现,反编译一些有此功能的app后发现MIUI并没有什么特殊的权限,本来偷懒的话可以将其所有的权限复制到自己的应用中就行了,但本着app的友好性(权限越少越好),还是自己探索吧。既然MIUI没有,那应该就是android原生系统权限的问题了。那具体是哪个权限呢?网上没找到,那只能自己试了,不过android权限这么多,一个一个试工作量太大了,只好先挑些感觉比较有可能的试了,还不错,试了6个就搞定了。测试如下:

       不加权限,安装成功界面什么都没有
       加上android.permission.READ_SETTINGS什么都没有
       加上android.permission.WRITE_SETTINGS则有设置相关中的系统设置权限
       加上android.permission.CHANGE_CONFIGURATION什么都没有
       加上com.android.launcher.permission.WRITE_SETTINGS什么都没有
       加上android.permission.PROCESS_OUTGOING_CALLS什么都没有
       加上android.permission.SYSTEM_ALERT_WINDOW则有设置相关中的显示悬浮窗权限


    话说华为、锤子什么的也有类似问题,有知道解决方案的能在底下给个链接最好了,感谢感谢。

package com.example.text; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.media.projection.MediaProjectionManager; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.Settings; import android.util.Log; import android.view.View; import android.widget.Button; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import com.example.text.AI.FloatingBallService; import com.example.text.Class.goods; import com.example.text.SQL.DatabaseHelper; import com.example.text.SQL.Goods.Goods; import com.example.text.SQL.Goods.GoodsItem; import com.example.text.utils.Http; import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; import android.Manifest; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private static final int REQUEST_STORAGE_PERMISSION = 1; private DatabaseHelper dbHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // EdgeToEdge.enable(this); setContentView(R.layout.activity_main); // 检查存储权限 if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // 权限启,请求用户授权 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_STORAGE_PERMISSION); } else { // 权限启,继续执行创建数据库的操作 createDatabase(); } if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return; // 如果没有权限,直接退出服务 } //创建数据库 dbHelper = new DatabaseHelper(this); Intent captureIntent = ((MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE)) .createScreenCaptureIntent(); startActivityForResult(captureIntent, 101); Button button=findViewById(R.id.button2); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Settings.canDrawOverlays(MainActivity.this)) { startService(new Intent(MainActivity.this, FloatingBallService.class)); // ✅ 自动退到后台(模拟 Home 键) Intent homeIntent = new Intent(Intent.ACTION_MAIN); homeIntent.addCategory(Intent.CATEGORY_HOME); homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(homeIntent); } else { // 引导用户授权 Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); startActivity(intent); } } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == 101 && resultCode == RESULT_OK) { Intent service = new Intent(this, FloatingBallService.class); service.putExtra("code", resultCode); service.putExtra("data", data); startService(service); } } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == REQUEST_STORAGE_PERMISSION) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { // 用户授予了权限,继续执行创建数据库的操作 createDatabase(); } else { // 用户拒绝了权限,提示用户 Log.e("MainActivity", "存储权限被拒绝"); Toast.makeText(this, "存储权限被拒绝,无法继续操作", Toast.LENGTH_SHORT).show(); } } } private void createDatabase() { // 创建数据库 dbHelper = new DatabaseHelper(this); Log.d("MainActivity", "数据库创建成功"); } } 2025-07-18 09:17:38.018 2569-2630 MiEvent system_server E report:open miev fail, EventId 901003004 -t 1752801458 -paraList {"ActivityName":"com.example.text.MainActivity","Duration":10126,"PackageName":"com.example.text"} ---------------------------- PROCESS ENDED (10638) for package com.example.text ---------------------------- 2025-07-18 09:17:40.058 4285-5371 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=10275 userId=0 windowMode=1 baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.example.text/com.example.text.MainActivity} } 2025-07-18 09:17:40.416 1425-1425 vendor.qti...al-service ven...qti.hardware.perf-hal-service E ExtendedPerfBoost: extended_perfboost_verification() 738: Ok, set boost params. hintid=4225 hinttype=1 prio=3, clientpid=2569 packagename=com.example.text params=boost:1 cpu0:1804800 cpu4:2496000 cpu7:2592000 cpumask:ff 2025-07-18 09:17:40.459 10872-10872 Zygote usap64 E process_name_ptr:10872 com.example.text 2025-07-18 09:17:40.523 27603-3228 SuggestManager com.miui.securitycenter.remote E openApp name = com.example.text 2025-07-18 09:17:40.534 27603-28288 AntiFraud com.miui.securitycenter.remote E hookDetectUnsafeAppStart error, android.content.pm.PackageManager$NameNotFoundException: com.example.text at android.app.ApplicationPackageManager.getApplicationInfoAsUser(ApplicationPackageManager.java:515) at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:498) at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:492) at w2.b.f(Unknown Source:12) at w2.b$c.onForegroundInfoChanged(Unknown Source:21) at com.miui.gamebooster.mutiwindow.b$a.onForegroundInfoChanged(Unknown Source:152) at miui.process.IForegroundInfoListener$Stub.onTransact(IForegroundInfoListener.java:86) at android.os.Binder.execTransactInternal(Binder.java:1351) at android.os.Binder.execTransact(Binder.java:1282) 2025-07-18 09:17:40.546 8279-10833 SuggestManager com.miui.securitycenter.remote E openApp name = com.example.text 2025-07-18 09:17:40.549 4285-5371 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=10276 userId=0 windowMode=1 baseIntent=Intent { act=android.intent.action.MAIN flag=268435456 cmp=ComponentInfo{com.example.text/com.example.text.MainActivity} } ---------------------------- PROCESS STARTED (10872) for package com.example.text ----------------------------
最新发布
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值