#xamarin #xamarin.forms #xamarin.android
Вопрос:
У меня проблема, которую мой приемник не принимает… Как странно…
Мне кажется, что я читаю все остальные посты на stackoverflow, но ничего не работает.
Цель-Android 10, устройство также работает под управлением Android 10, и это мой приемник.
[BroadcastReceiver(Name = "com.meac.ReaderService.BootComplete", Enabled = true, Exported = true, Permission = "RECEIVE_BOOT_COMPLETED")]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class BootComplete : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
string text = "Boot completed";
ToastLength duration = ToastLength.Short;
var toast = Toast.MakeText(context, text, duration);
toast.Show();
/* if (intent.Action.Equals(Intent.ActionBootCompleted))
{
Intent s = new Intent(context, typeof(ReaderService));
context.StartService(s);
Intent s2 = new Intent(context, typeof(GuardService));
context.StartService(s);
// StartRDP(context);
}*/
}
}
И это мой манифест, который должен содержать все необходимые разрешения.
<?xml version="1.0" encoding="utf-8"?>
<!--
This code was generated by a tool.
It was generated from C:Userstomas.filipsourcereposReaderService_V2ReaderService_V2PropertiesAndroidManifest.xml
Changes to this file may cause incorrect behavior and will be lost if
the contents are regenerated.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.meac.ReaderService" android:installLocation="internalOnly" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="27" android:targetSdkVersion="29" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
<uses-permission android:name="android.permission.INSTANT_APP_FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.PERSISTENT_ACTIVITY" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application android:name="android.app.Application" android:allowBackup="true" android:appComponentFactory="androidx.core.app.CoreComponentFactory" android:debuggable="true" android:extractNativeLibs="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
<receiver android:name="com.meac.ReaderService.BootComplete" android:enabled="true" android:exported="true" android:permission="RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="crc64bdb27b5d294e9832.GuardService" />
<activity android:name="crc64bdb27b5d294e9832.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="crc64bdb27b5d294e9832.ReaderService" />
<activity android:name="crc646957603ea1820544.MediaPickerActivity" android:configChanges="orientation|screenSize|uiMode" />
<service android:name="crc64396a3fe5f8138e3f.KeepAliveService" />
<receiver android:name="crc64a0e0a82d0db9a07d.BatteryBroadcastReceiver" android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" />
<receiver android:name="crc64a0e0a82d0db9a07d.EnergySaverBroadcastReceiver" android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" />
<receiver android:name="crc64a0e0a82d0db9a07d.ConnectivityBroadcastReceiver" android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" />
<activity android:name="crc64a0e0a82d0db9a07d.IntermediateActivity" android:configChanges="orientation|screenSize" />
<provider android:name="xamarin.essentials.fileProvider" android:authorities="com.meac.ReaderService.fileProvider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/xamarin_essentials_fileprovider_file_paths" />
</provider>
<activity android:name="crc64a0e0a82d0db9a07d.WebAuthenticatorIntermediateActivity" android:configChanges="orientation|screenSize" />
<provider android:name="mono.MonoRuntimeProvider" android:authorities="com.meac.ReaderService.mono.MonoRuntimeProvider.__mono_init__" android:exported="false" android:initOrder="1999999999" />
<!-- suppress ExportedReceiver -->
<receiver android:name="mono.android.Seppuku">
<intent-filter>
<action android:name="mono.android.intent.action.SEPPUKU" />
<category android:name="mono.android.intent.category.SEPPUKU.com.meac.ReaderService" />
</intent-filter>
</receiver>
</application>
</manifest>
Я вручную включил разрешение «Отображение поверх других приложений».
Я потратил на это сегодня 6 часов и совершенно растерялся.
Это будет на 100% что-то глупое.
Надеюсь, что кто-то, кто может это понять, сможет разобраться в этом. Спасибо.
Комментарии:
1. Вы тестировали свой ресивер на более старой версии до Android 8.0? В Android 8.0 (API 26 и выше) Google ввел ограничения на то, что могут делать приложения, пока пользователи не взаимодействуют с ними напрямую. Проверьте ограничения: developer.android.com/about/versions/oreo/background
Ответ №1:
Исправлено это путем добавления категорий в фильтр намерений.
[IntentFilter(actions: new[] { Intent.ActionBootCompleted }, Categories = new []{ Intent.CategoryDefault })]