标签: android-12

检查应用程序是否可以在 Android 12+ 上在后台启动前台服务

在应用程序实际尝试执行并获取之前,有什么方法可以检查我的应用程序是否可以在 Android 12 上在后台启动前台服务ForegroundServiceStartNotAllowedException

某种方法检查至少满足一个条件https://developer.android.com/guide/components/foreground-services#background-start-restriction-exemptions

我在活动中将后台服务作为前台启动

try {
    context.bindService( // p.s. this context of application, it's bounded to app process instead of activity context
        getServiceIntent(context),
        object : ServiceConnection {
            override fun onServiceConnected(
                className: ComponentName,
                service: IBinder
            ) {
                // service is running in background
                startForegroundService(context)
                // service should be in foreground mode (at least it should be very soon)
                (service as LocalBinder).getService().initialize()
                context.unbindService(this)
                bindServiceInProgress.set(false)
            }

            override fun onServiceDisconnected(arg0: ComponentName) {
                bindServiceInProgress.set(false)
            }
        },
        AppCompatActivity.BIND_AUTO_CREATE
    )
} catch …
Run Code Online (Sandbox Code Playgroud)

android foreground-service android-12

5
推荐指数
1
解决办法
4187
查看次数

Xamarin.Android 没有“android:exported”属性设置错误

当 Xamarin.Android 设置为 Android 12 时,我收到

“您上传的 APK 或 Android App Bundle 具有活动、活动别名、服务或带有 Intent 过滤器的广播接收器,但没有设置“android:exported”属性。此文件无法安装在 Android 12 或更高版本上。请参阅:developer.android.com/about/versions/12/behavior-changes-12#exported”

将 APK 上传到 Google Play 管理中心以发布新版本时出错。

我已将导出属性添加到我的活动和服务中,但仍然设置此错误。

[Activity(Label = "@string/AppDrawerName", Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_launcher_round", Theme = "@style/MainTheme", MainLauncher = true, Exported = false, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait)]

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
Run Code Online (Sandbox Code Playgroud)

服务

[Service(Exported = true)]
    public class BarcodeService : IBarcodeService
    {
Run Code Online (Sandbox Code Playgroud)

从编译输出我可以看到下面的消息

命名空间“com.google.android.gms.stats”用于:AndroidManifest.xml、AndroidManifest.xml。

android:exported 需要为元素 <service#crc640921eac73192168e.PNMessagingService> 显式指定。android:exported当相应组件定义了意图过滤器时,面向 Android 12 及更高版本的应用需要指定显式值 。 有关详细信息,请参阅 …

android xamarin.android xamarin android-12

5
推荐指数
2
解决办法
6761
查看次数

Android 12:检测用户是否禁用/启用相机和麦克风

借助新的 Android 12 操作系统,用户现在可以完全禁用所有应用程序中的麦克风和摄像头使用。这其实是一件好事,让用户轻松掌控隐私。

如果应用程序启动并有权使用麦克风和摄像头,并且用户已禁用对这些硬件的所有访问权限,Android 12 会自动弹出警报,要求用户重新启用麦克风或摄像头,或者继续该应用程序的硬件已禁用。

此外,在创建时,应用程序可以简单地检查何时开始查看所需的硬件是否已启用,并且还可以进一步提示用户或根据应用程序认为合适的情况处理条件。

但是,如果用户在应用程序运行禁用麦克风或摄像头怎么办?我似乎找不到类似事件的任何接口onMicrophoneEnabled(),甚至找不到此类事件的广播。

可以在每次onResume()调用时进行检查,但我希望有一个更优雅的解决方案。

如果有人知道当用户以任何方式进行更改时我的应用程序可以使用某些东西来捕获此信息,请告诉我。

camera android microphone android-12

5
推荐指数
1
解决办法
2763
查看次数

使用 &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt; 时,Android 12 会阻止触摸

我用来<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />显示一个覆盖在其他应用程序上的弹出窗口,但 android 12 阻止了触摸。根据文档,它会阻止触摸事件,我如何允许在 android 12 上进行触摸。

这是 android 12 行为更改触摸事件的链接 https://developer.android.com/about/versions/12/behavior-changes-all#untrusted-touch-events

import android.app.Service;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.hardware.input.InputManager;
import android.os.IBinder;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;


public class FloatWidgetService extends Service {

    private WindowManager mWindowManager;
    private View mFloatingWidget;

    public FloatWidgetService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        final WindowManager.LayoutParams params;
        mFloatingWidget = LayoutInflater.from(this).inflate(R.layout.layout_floating_widget, null);
        mFloatingWidget.setFilterTouchesWhenObscured(true);
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, …
Run Code Online (Sandbox Code Playgroud)

android android-studio android-12

5
推荐指数
1
解决办法
2081
查看次数

How to disable Clipboard editor overlay Android Emulator API 33?

How can i disable Clipboard editor overlay, that is enabled by default in Android Emulator API 33?. It is very annoying while debugging apps.It always popup over my debugging apps, and i have to close this every time to do something in my debugging app.

在此输入图像描述

android clipboardmanager android-12

5
推荐指数
1
解决办法
2105
查看次数

如何在 Android 12 的 SplashScreen api 中使用动态颜色?

我试图使 android 12 启动屏幕的背景使用 @android:color/system_neutral1_900 作为背景,但正如我所看到的,颜色仅在启动屏幕之后加载。有什么办法可以在启动屏幕上使用它吗?

<style name="Theme.App.SplashScreen" parent="Theme.SplashScreen">
    <!-- Set the splash screen background, animated icon, and animation duration. -->
    <item name="windowSplashScreenBackground">@android:color/system_neutral1_900</item>
</style>
Run Code Online (Sandbox Code Playgroud)

颜色不会出现,它使用默认的灰色。我还尝试了其他 system_ 颜色,出现了相同的结果。使用 @android:color/black 或十六进制颜色可以。

android android-12 android-api-31 android-splashscreen

5
推荐指数
1
解决办法
894
查看次数

显示启动屏幕时后退按钮不响应(适用于 Android 12 的新启动 API)

自从 Android 12 的新 Android Splash Screen API 开始,在显示闪屏时后退按钮不再响应,看起来 UI 线程已完全接管,我无法重新启用后退按钮,这是一个问题,例如,如果用户不小心打开应用程序,他通常会单击后退按钮,应用程序关闭后问题就会立即解决(或者至少这是我的应用程序在这个新 API 之前的行为),但现在这是一个糟糕的用户体验。

所以我想知道您是否找到了解决此问题的方法并在加载数据时显示启动屏幕时启用“后退”按钮?

我测试了很多教程并下载了源代码,但在所有教程中,后退按钮都没有响应。

例如这个:https: //github.com/philipplackner/SplashScreenAndroid12

感谢您的帮助,非常感谢。

android back-button android-12 android-splashscreen

5
推荐指数
0
解决办法
165
查看次数

Android12中的数据提取规则

当我们不想维护SharedPreferences或任何备份文件时,我们可以直接设置android:allowBackup="false"AndroidManifest.xml.
android:allowBackup="false"在 Android12 中已弃用。尽管它已被弃用,我们仍然可以继续使用它cloud-based backup。例如,如果我们正在使用SharedPreferences,则删除我们的应用程序并重新安装后,它们SharedPreferences就会消失。您可以从这里找到信息。

所以,我想了解的是D2D。在Android12中,Android系统自动将文件从旧设备发送到新设备(D2D)。我想阻止系统SharedPreferences默认自动发送文件(如)。所以,我必须确定dataExtractionRules 哪些文件包含或不包含。

我想要做的是排除所有文件。这意味着我可以将应用程序传输到新设备,但没有数据或缓存,就像我刚刚下载了新应用程序一样。那么,我该如何写作dataExtractionRules来实现它呢?

请检查以下代码我做了什么。

数据提取规则.xml

<?xml version="1.0" encoding="utf-8"?>
<data-extraction-rules>

<!-- <cloud-backup> I don't write cloud-backups in here
 because i can still use android:allowBackup="false" </cloud-backup> -->
    
    <device-transfer>
        <exclude domain="root" path="where?" />
        <exclude domain="file" path="where?" />
        <exclude domain="database" path="where?" />
        <exclude domain="sharedpref" path="com.google.android.gms.appid.xml" />
        <exclude domain="sharedpref" path="user_pref.xml" />
        <!-- <exclude domain="external" path="where?" /> --> …
Run Code Online (Sandbox Code Playgroud)

android android-manifest android-backup-service android-12

5
推荐指数
1
解决办法
2852
查看次数

以 S+(版本 33)为目标需要指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一

应用程序在运行时崩溃并出现以下错误:

面向 S+(版本 31 及更高版本)要求在创建 PendingIntent 时指定 FLAG_IMMUTABLE 或 FLAG_MUTABLE 之一。强烈考虑使用 FLAG_IMMUTABLE,仅当某些功能依赖于可变的 PendingIntent 时才使用 FLAG_MUTABLE,例如,如果需要与内联回复或气泡一起使用。

我尝试了所有可用的解决方案,但应用程序在 Android 12 上仍然崩溃。

private Notification buildNotification() {
    int playButtonResId = isPaused ? R.drawable.ic_play_arrow_white_24dp : R.drawable.ic_pause_white_24dp;

    PendingIntent clickIntent = PendingIntent.getActivity(
            this, 1,
            new Intent(this, MainActivity.class),
            PendingIntent.FLAG_IMMUTABLE);
Run Code Online (Sandbox Code Playgroud)

java android android-pendingintent exoplayer2.x android-12

5
推荐指数
1
解决办法
1007
查看次数

以编程方式使用 Android 12 在三星上打开辅助功能权限屏幕

我的 Android 应用程序请求可访问性的权限。在旧版本的 Android 上,下面的代码会打开正确的辅助功能权限屏幕。但在 Android 12 的三星上测试,它不起作用。

private void launchPermission() {
        AppOpsManager ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        Intent intent = new Intent("android.settings.ACCESSIBILITY_SETTINGS");
        startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)

你能帮我解决这个问题吗?

android accessibilityservice android-12

5
推荐指数
1
解决办法
489
查看次数