- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只兼职进行 Android 开发(考虑到 API 的许多微妙之处和低级别性,这似乎具有挑战性),并且当我的应用程序在后台时接收通知时遇到问题。我的目标是 Android 8.1。我的应用程序碰巧使用 Azure 和 Xamarin,但我不知道这些细节是否是问题所固有的。
如果我的应用程序在后台运行,有时会显示通知,有时我的应用程序会因以下错误而崩溃:
2019-03-06 09:12:24.486 9495-9702/? D/tyresense.azurelistenerservice: OnMessage() done
2019-03-06 09:12:28.278 1548-3232/? W/ActivityManager: Background start not allowed: service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.rimex.tyresense cmp=com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService (has extras) } to com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService from pid=9495 uid=10173 pkg=com.rimex.tyresense
2019-03-06 09:12:28.341 9495-9495/? I/MonoDroid: Java.Lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.rimex.tyresense cmp=com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService (has extras) }: app is in background uid UidRecord{d582ba5 u0a173 RCVR bg:+1m0s848ms idle procs:1 seq(0,0,0)}
2019-03-06 09:12:28.342 9495-9495/? I/MonoDroid: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.rimex.tyresense cmp=com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService (has extras) }: app is in background uid UidRecord{d582ba5 u0a173 RCVR bg:+1m0s848ms idle procs:1 seq(0,0,0)}
2019-03-06 09:12:28.347 9495-9495/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rimex.tyresense, PID: 9495
java.lang.RuntimeException: Unable to start receiver md5bf34da605c12d097dc5a495af95e9376.TyreSenseBroadcastReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.rimex.tyresense cmp=com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService (has extras) }: app is in background uid UidRecord{d582ba5 u0a173 RCVR bg:+1m0s848ms idle procs:1 seq(0,0,0)}
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3285)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1713)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.rimex.tyresense cmp=com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService (has extras) }: app is in background uid UidRecord{d582ba5 u0a173 RCVR bg:+1m0s848ms idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1536)
at android.app.ContextImpl.startService(ContextImpl.java:1492)
at android.content.ContextWrapper.startService(ContextWrapper.java:650)
at android.content.ContextWrapper.startService(ContextWrapper.java:650)
at md513d040a829b3f298fbeeee5a6e2c042a.GcmBroadcastReceiverBase_1.n_onReceive(Native Method)
at md513d040a829b3f298fbeeee5a6e2c042a.GcmBroadcastReceiverBase_1.onReceive(GcmBroadcastReceiverBase_1.java:29)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3278)
at android.app.ActivityThread.-wrap17(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1713)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
2019-03-06 09:12:28.348 2761-2761/? W/GCM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.rimex.tyresense (has extras) }
2019-03-06 09:12:28.353 9495-9495/? E/tyresense.splashscreen: System.UnhandledExceptionEventArgs
2019-03-06 09:12:28.357 1548-7265/? W/ActivityManager: Force finishing activity com.rimex.tyresense/md5bf34da605c12d097dc5a495af95e9376.MainActivity
2019-03-06 09:12:28.363 1548-1632/? I/ActivityManager: Showing crash dialog for package com.rimex.tyresense u0
我看到这样的文章:https://blog.xamarin.com/replacing-services-jobs-android-oreo-8-0/
但我不清楚问题到底是什么,所以我不知道这是否能解决问题。
也许在这里?
using System;
using System.Collections.Generic;
using Android.App;
using Android.Content;
using Android.Util;
using Gcm.Client;
using WindowsAzure.Messaging;
using SharedMobile; // keep it simple, the app might not be running
using MyApp.Android; // we need to reference ourselves...
using Android.Support.V4.App;
using Android.Content.PM;
using System.Threading.Tasks;
[assembly: Permission(Name = "@<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0959484a42484e4c564748444c4927796c7b64607a7a606667274a3b4d" rel="noreferrer noopener nofollow">[email protected]</a>_MESSAGE")]
[assembly: UsesPermission(Name = "@<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9e9f8faf2f8fefce6f7f8f4fcf997c9dccbd4d0cacad0d6d797fa8bfd" rel="noreferrer noopener nofollow">[email protected]</a>_MESSAGE")]
[assembly: UsesPermission(Name = "com.google.android.c2dm.permission.RECEIVE")]
[assembly: Xamarin.Forms.Dependency(typeof(DependencyListener))]
namespace MyApp.Android
{
[BroadcastReceiver(Permission = Constants.PERMISSION_GCM_INTENTS)]
[IntentFilter(new string[] { Constants.INTENT_FROM_GCM_MESSAGE }, Categories = new string[] { "@PACKAGE_NAME@" })]
[IntentFilter(new string[] { Constants.INTENT_FROM_GCM_REGISTRATION_CALLBACK }, Categories = new string[] { "@PACKAGE_NAME@" })]
[IntentFilter(new string[] { Constants.INTENT_FROM_GCM_LIBRARY_RETRY }, Categories = new string[] { "@PACKAGE_NAME@" })]
public class MyAppBroadcastReceiver : GcmBroadcastReceiverBase<AzureListenerService>
{
// this declaration somehow enables messages
}
[Service]
public class AzureListenerService : GcmServiceBase // this service might be started at system boot, when the app is otherwise not active
{
const string TAG = "MyApp.azurelistenerservice";
const string HUBNAME = "myhubname";
const string CONNECTION =
"Endpoint=sb://MyApp.servicebus.windows.net/;SharedAccessKeyName=DefaultListenSharedAccessSignature;SharedAccessKey=secretstuff...";
public const string GcmProjectNumber = "1234567890";
private static NotificationHub noteHub = null;
public AzureListenerService() : base(GcmProjectNumber)
{
}
// need client and area ids before this is called. Application.Context is not available if called from system boot
public static void InitializeAzure(Context context = null)
{
try
{
if (context == null)
context = Application.Context;
var enabled = NotificationManagerCompat.From(context).AreNotificationsEnabled();
SharedMobile.API.ApiService.Instance.NotificationsEnabled(enabled);
if (enabled)
{
GcmClient.CheckDevice(context);
GcmClient.CheckManifest(context);
GcmClient.Register(context, GcmProjectNumber);
}
}
catch (Exception ex)
{
Log.Error(TAG, ex.Message);
Messenger.SendException(ex.Message);
}
}
// incoming GCM registration
protected override void OnRegistered(Context context, string token)
{
try
{
noteHub = new NotificationHub(HUBNAME, CONNECTION, context);
var customerId = Int32.Parse(PropertyHelper.ClientId);
var tags = BuildTagList(customerId, PropertyHelper.AreaIds);
noteHub.Register(token, tags.ToArray());
Messenger.RegisterDevice(token);
}
catch (Exception ex)
{
Log.Error(TAG, "OnRegistered() " + ex.Message); // ignore register failure when using the Android emulator
}
}
protected override void OnMessage(Context context, Intent intent)
{
try
{
var areaIds = PropertyHelper.AreaIds;
if (string.IsNullOrWhiteSpace(areaIds)) // in case the user logged out
return;
new Notifications().CreateEventNotification(intent);
}
catch (Exception ex)
{
Log.Error(TAG, "OnMessage() " + ex.Message);
}
}
protected List<string> BuildTagList(int clientId, string areaIds)
{
var list = new List<string>();
list.Add($"client_{clientId}");
foreach (var id in areaIds.Split(','))
list.Add($"area_{id}");
return list;
}
protected override void OnUnRegistered(Context context, string registrationId)
{
Log.Error(TAG, "OnUnRegistered(): " + registrationId);
}
protected override bool OnRecoverableError(Context context, string errorId)
{
Log.Error(TAG, "OnRecoverableError(): " + errorId);
return base.OnRecoverableError(context, errorId);
}
protected override void OnError(Context context, string errorId)
{
Log.Error(TAG, "OnError(): " + errorId);
}
}
}
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Support.V4.App;
using Android.Support.V4.Content;
using Android.Util;
using Exception = System.Exception;
namespace My.Android
{
internal class Notifications
{
const string TAG = "My.notifications";
const string TITLE = "Application is running";
const string DESC = "Tap to view";
const int MainProgramNotificationId = 775566;
// unique ID for our notification:
static readonly string CHANNEL_ID = "My_channel_23";
static readonly string CHANNEL_NAME = "[My_channel]";
internal void CreateProgramIcon_on_hold(Intent intent)
{
var extras = new Bundle();
extras.PutString("scopeDescription", TITLE);
extras.PutString("stateDescription", DESC);
intent.PutExtras(extras);
ShowNotification(intent.Extras, false);
}
internal void CreateEventNotification(Intent extra)
{
if (extra.Extras != null && !extra.Extras.IsEmpty)
ShowNotification(extra.Extras, true);
var notificationId = extra?.Extras?.GetString("notification-id", null);
if (notificationId != null && notificationId.Length > 0)
SharedMobile.API.ApiService.NotificationConfirmation(notificationId);
}
private void ShowNotification(Bundle extras, bool autoCancel)
{
try
{
string title = TITLE;
string description = DESC;
if (extras != null && !extras.IsEmpty)
{
title = extras.GetString("scopeDescription", null);
description = extras.GetString("stateDescription", "");
}
Intent intent = new Intent(Application.Context, typeof(SplashScreen));
BuildNotification(intent, extras, title, description, autoCancel);
}
catch (Exception ex)
{
Log.Debug(TAG, ex.Message);
}
}
private void BuildNotification(Intent intent, Bundle extras, string title, string description, bool autoCancel)
{
bool onGoing = !autoCancel;
int icon = IconId(null, null); // code not shown
intent.AddFlags(ActivityFlags.ReorderToFront);
var pendingIntent = PendingIntent.GetActivity(Application.Context, 0, intent, PendingIntentFlags.UpdateCurrent);
CreateNotificationChannel(autoCancel);
var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
NotificationCompat.Builder builder = new NotificationCompat.Builder(Application.Context, CHANNEL_ID);
builder.SetSmallIcon(icon)
.SetContentTitle(title)
.SetContentText(description)
.SetSmallIcon(Resource.Drawable.notification_icon)
.SetAutoCancel(autoCancel)
.SetOngoing(onGoing)
.SetContentIntent(pendingIntent);
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
builder.SetColor(ContextCompat.GetColor(Application.Context, Resource.Color.exBackgroundColor));
string utcTicks = null;
if (extras != null)
utcTicks = extras.GetString("utcTicks", null);
if (utcTicks != null)
{
var ticks = Int64.Parse(utcTicks);
DateTimeOffset dto = new DateTimeOffset(ticks, TimeSpan.Zero);
builder.SetWhen(dto.ToUnixTimeMilliseconds());
}
else
builder.SetShowWhen(true);
notificationManager?.Notify(MainProgramNotificationId, builder.Build());
}
private void CreateNotificationChannel(bool evnt)
{
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{
// There is no need to create a notification channel on older versions of Android.
return;
}
NotificationImportance ni;
if (evnt)
ni = NotificationImportance.Default;
else
ni = NotificationImportance.Low;
var channel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, ni)
{
Description = "My App",
LockscreenVisibility = NotificationVisibility.Private,
};
var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
notificationManager.CreateNotificationChannel(channel);
}
string FormatTimeStamp(string utcTicks)
{
try
{
var ticks = Int64.Parse(utcTicks);
DateTimeOffset dto = new DateTimeOffset(ticks, TimeSpan.Zero);
return dto.ToLocalTime().ToString("MM/dd HH:mm:ss");
}
catch (Exception)
{
return string.Empty;
}
}
bool IgnoreActionProcess(string actionProcessId, int ackedProcessId)
{
try
{
if (int.Parse(actionProcessId) == ackedProcessId)
return true;
}
catch (Exception ex)
{
Log.Debug(TAG, $"int parse: {actionProcessId} {ex.Message}");
}
return false;
}
}
}
更新:我将公共(public)类 AzureListenerService : GcmServiceBase 中的 OnMessage 更改为不执行任何操作,但它仍然崩溃:
未处理的异常:Java.Lang.IllegalStateException:不允许启动服务 Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x1000010 pkg=com.mycompany.myapp cmp=com.mycompany.myapp/md5bf34da605c12d097dc5a495af95e9376.AzureListenerService (有额外功能) }: 应用程序处于后台 uid UidRecord{d45626f u0a173 RCVR bg:+1m29s589ms 空闲更改:未缓存的过程:1 seq(0,0,0)} 发生
更新我实现了 JobScheduler,这没有什么区别。此外,该应用程序必须在后台运行“一段时间”,然后问题总会发生。我还更改了我的应用程序,使其在通知到达时不执行任何操作(但记录),但它仍然崩溃。
更新我得到了这个工作:https://developer.xamarin.com/samples/monodroid/Firebase/FCMNotifications/通过将其“按原样”添加到我的 firebase 帐户,下载 google-services.json 并使用 http://pushtry.com/ 进行测试。 Azure 门户测试发送尚未成功。希望将 FCMNotifications 中的代码合并到我的应用程序中,如果我能让 Azure 正常工作的话...
最佳答案
Android 8.0(API 级别 26)及更高版本对后台服务有限制。它包括对具体方法的以下更改:
如果面向 Android 8.0 的应用尝试在不允许创建后台服务的情况下使用该方法,则 startService() 方法现在会引发 IllegalStateException。新的 Context.startForegroundService() 方法启动前台服务。即使应用程序处于后台,系统也允许应用程序调用 Context.startForegroundService()。但是,应用程序必须在创建服务后五秒内调用该服务的 startForeground() 方法。
关于android - 应用程序有时会崩溃并显示 "Background start not allowed: service Intent",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55029280/
我正在 Angular js和sails.js(node.js框架)之间的cors问题上挣扎 我尝试修复错误:XMLHttpRequest无法加载http://localhost:1337/en/au
我在我的应用程序中动态创建一个 iframe,结果如下所示: 这样的沙箱配置是否安全(特别是允许将 iframe 内容视为来自同一来源)? 最佳答案 正如 Namey 评论的那样,allow-sam
突然,似乎没有更改我的网络应用程序中的任何内容,我在 Chrome 中打开它时开始收到 CORS 错误。我尝试添加 Access-Control-Allow-Origin: *标题。然后我得到这个错误
我正在使用 Ionic Framework 开发应用程序。 在后端,我为 api 编写了一个 Flask 应用程序,如下所示: @API.route("/saverez",methods=["POST
我正在尝试从 onesignal api 发送 POST 请求 代码 axios({ method: 'post', url: 'https://onesignal.com/api/v1/no
我一直在寻找一些类似的问题来寻找答案,但我找不到。我有一个带有 express 的 node.js 服务器: app.use(function(req, res, next) { res.head
我使用 Google Cloud Functions 创建了一个 API 端点,并试图从 JS 获取函数中调用它。 我遇到了我很确定与 CORS 或输出格式有关的错误,但我不确定发生了什么。其他一些
当我尝试从我的 Angular 6 应用程序访问 Webhdfs 时,我收到如下所示的错误。在我看来,我几乎尝试了所有方法,包括更改 core-site.xml 和 hdfs-site.xml 中的设
我刚刚学习 ajax 和 cors 一些东西,现在我想知道 chrome 插件“allow-control-allow-origin”是如何工作的。 当我尝试执行正常的 ajax 请求时,控制台显示错
我正在努力理解如何允许用户在列表中创建新记录,但只允许创建者更新他们自己的帖子。 例如。以下结构: post { post1: { author: "user1"
我们的网络上有 2 个内部(内联网)Windows 服务器,仅适用于本地网络。在 server1 上安装了 Spark,我们可以在其中查询 Jabber 信息,如下所示: http://server1
所以在 routing.yml 中我定义了以下路由,以便编辑和删除特定设置: 路由.yml: settings.editDefaults: path: settings/{id}/d
我哪里出错了 title $.get("http://api.angel.co/1/tags/1654/startups?callback=aaa", function(data
首先,对您可能犯的语法错误表示歉意。我的英语不是很好。 我是 Spring 新手,我正在尝试创建基本身份验证安全性。 我正在尝试配置一个端点具有公共(public)访问权限,而其他端点则具有用户访问权
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: NULL in MySQL (Performance & Storage) 如果出现以下情况,您是否强烈建议取消选中
我正在尝试将我的一个网站中的内容加载到另一个网站中: $('#include-from-outside').load('http://lujanventas.com/plugins/banne
这里出了什么问题? OPTIONS https://twitter.com/oauth/request_token 401 (Unauthorized) jsOAuth-1.3.4.js:483 XM
allow-control-allow-origin : * header 存在于 API 响应中,但浏览器仍显示错误。网络 403 错误。 这是来自 API 的示例响应 header : Acces
在 Go 中制作 slice 时的 capacity 参数对我来说意义不大。例如, aSlice := make([]int, 2, 2) //a new slice with length and
Gitlab 保护分支中“允许推送”和“允许 merge ”是什么意思 最佳答案 引用 Gitlab Documentation here Using the "Allowed to push" an
我是一名优秀的程序员,十分优秀!