我正在为自己创建一个应用程序,我需要我的服务在设备重新启动时工作。我在这里做了我的代码。
namespace Corporate_messenger.Droid.Broadcast
{
[BroadcastReceiver(Name = "com.companyname.corporate_messenger.BootReceiver", Enabled = true, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
private void Start1(Context context)
{
Intent mycallIntent = new Intent(context, typeof(MainActivity));
mycallIntent.AddFlags(ActivityFlags.NewTask);
Android.App.Application.Context.StartActivity(mycallIntent);
}
public override void OnReceive(Context context, Intent intent)
{
try
{
var intentService = new Intent(context, typeof(NotoficationService));
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
SpecialData.RestartResponse = true;
context.StartForegroundService(intentService);
}
else
{
context.StartService(intentService);
// Flag_On_Off_Service = true;
}
}
catch(Exception ex)
{
Log.Error("MyLog", ex.Message);
}
} // OnReceive
}
}
我还请求了使用文件夹和麦克风的权限。
public async Task Permission()
{
var PermissionsStrorage_Write = await Permissions.CheckStatusAsync<Permissions.StorageWrite>();
var PermissionsInternet = await Permissions.CheckStatusAsync<Permissions.NetworkState>();
var PermissionsStrorage_Read = await Permissions.CheckStatusAsync<Permissions.StorageRead>();
var PermissionsRecord = await Permissions.CheckStatusAsync<Permissions.Microphone>();
if (PermissionsInternet != PermissionStatus.Granted)
{
PermissionsInternet = await Permissions.RequestAsync<Permissions.NetworkState>();
}
if (PermissionsRecord != PermissionStatus.Granted)
{
PermissionsRecord = await Permissions.RequestAsync<Permissions.Microphone>();
}
if (PermissionsStrorage_Write != PermissionStatus.Granted && PermissionsStrorage_Read != PermissionStatus.Granted)
{
PermissionsStrorage_Write = await Permissions.RequestAsync<Permissions.StorageWrite>();
PermissionsStrorage_Read = await Permissions.RequestAsync<Permissions.StorageRead>();
}
if (PermissionsStrorage_Write != PermissionStatus.Granted && PermissionsStrorage_Read != PermissionStatus.Granted)
{
return;
}
}
结果代码:
但是我遇到了一个问题,为了使我的服务在某些设备上正常工作,需要两个复选框。
现在我不明白如何询问用户这些权限,这样他就不用自己去设置了,也许应用程序可以自己打开这个页面,基本上小米手机都会出现这个问题,目前我在写android的应用程序,但是xamarin允许你写iOS的代码,所以以后我也会在那里添加这样的功能。
1条答案
按热度按时间eblbsuwk1#
这是这个问题的答案
如何进入其他设备的设置How to start Power Manager of all android manufactures to enable background and push notification?
只是我就是不明白怎么弄清楚旗的状况