我需要创建一个简单的通知,如果可能的话,它会与声音和图标一起显示在通知栏中?我还需要它与Android 2.2兼容,所以我发现NotificationCompat.Builder适用于4以上的所有API.如果有更好的解决方案,请随意提及.
notifications android android-notifications android-notification-bar
我将非常感谢有关如何处理操作系统查杀长期服务的一些指导.
业务场景:
应用程序记录BTT轨道,可能持续数小时.它还可以在地图上显示轨道以及相关统计数据.
应用程序用户界面使用户能够开始/停止跟踪记录并在地图上查看实时跟踪.
在开始跟踪记录之后,用户可以退出应用程序并关闭屏幕(以节省电量),并且只有服务将保持运行以保持记录更新到数据库(显示通知),直到用户再次启动活动并要求停止记录,这导致服务终止.
问题:
在可变时间(从40分钟到1个半小时)之后,录制服务在没有任何警告的情况下被杀死.由于BTT出场可能需要几个小时,这导致跟踪录音不完整.
一些其他信息:
服务以启动START_STICKY并获取PARTIAL_WAKE_LOCK,并在与主活动相同的过程中运行.
以用户定义的速率从1秒到几分钟获取(并记录)新位置.我从Android文档中了解到,这是长期运行服务的预期操作系统行为.
题:
拥有性能良好的应用程序以满足业务场景要求的最佳架构设计方法是什么?
我可以想到几个选项(我不喜欢它们中的任何一个),但我希望某人如何面对并解决类似问题的指导:
感谢所有能够就此主题分享一些智慧的人.
什么是一个动作添加到通知的正确方法API 23,因为addAction(int icon, CharSequence title, PendingIntent intent)已经过时?找不到任何例子,谢谢.
我的旧动作: .addAction(R.drawable.ic_prev, "Previous", prevPendingIntent)
在我的应用程序中,我需要向用户显示通知.通过在Android设备标题栏中显示图标和内容标题,以下代码段效果很好.
var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
var uiIntent = new Intent(this, typeof(MainActivity));
var notification = new Notification(Resource.Drawable.AppIcon, title);
notification.Flags = NotificationFlags.AutoCancel;
notification.SetLatestEventInfo(this, title, desc, PendingIntent.GetActivity(this, 0, uiIntent, 0));
notificationManager.Notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
当我尝试构建用于部署应用程序的包时,出现以下错误:
Android.App.Notification.SetLatestEventInfo(Android.Content.Context,string,string,Android.App.PendingIntent)'已过时:'已弃用'
所以我找到了我应该使用的代码片段,它显示状态栏中的图标而不是内容标题
Intent resultIntent = new Intent(this, typeof(MainActivity));
PendingIntent pi = PendingIntent.GetActivity(this, 0, resultIntent, 0);
NotificationCompat.Builder builder = new NotificationCompat.Builder(Forms.Context)
.SetContentIntent(pi)
.SetAutoCancel(true)
.SetContentTitle(title)
.SetSmallIcon(Resource.Drawable.AppIcon)
.SetContentText(desc); //This is the icon to display
NotificationManager nm = GetSystemService(Context.NotificationService) as NotificationManager;
nm.Notify(_TipOfTheDayNotificationId, builder.Build());
Run Code Online (Sandbox Code Playgroud)
我需要在新的代码片段中设置什么才能在Android设备状态栏中显示内容标题?
我的项目build.gradle是:
...
compileSdkVersion 21
buildToolsVersion "22.0.1"
...
Run Code Online (Sandbox Code Playgroud)
所有的事情都没关系,但是当我把它改成最新的compileSdkVersion 23和buildToolsVersion "23.0.1"一些类如:
Browser.BookmarkColumns cannot resolve "BookmarkColumns"
Run Code Online (Sandbox Code Playgroud)
要么
notification.setLatestEventInfo(..) cannot resolve "setLatestEventInfo"
Run Code Online (Sandbox Code Playgroud)
和...
这最后一个构建工具版本有什么问题,我该如何解决?