c# - Xamarin Android BootReceiver 检查包
问题描述
当我自己的包安装/更新时,我尝试进行 BootReceiver 调用,但我似乎无法找到如何检查调用的原因是因为代码所在的包,还是另一个已更新的应用程序。这样的东西是否已经存在,如果存在,如何使用它?
这是代码:
[BroadcastReceiver(Enabled = true, Exported = true, DirectBootAware = true)]
[IntentFilter(new string[] { Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted, Intent.ActionPackageReplaced, "android.intent.action.QUICKBOOT_POWERON", "com.htc.intent.action.QUICKBOOT_POWERON" })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent timedIntent = new Intent(context, typeof(ITM.NotificationService));
//add missed traffic before program started with boot
if(intent.Action.Equals(Intent.ActionBootCompleted) || intent.Action.Equals(Intent.ActionLockedBootCompleted))
{
timedIntent.PutExtra("aDownBootup", TrafficStats.TotalRxBytes);
timedIntent.PutExtra("aUpBootup", TrafficStats.TotalTxBytes);
}
if (ITM.NotificationService.isStarted == false)
{
Application.Context.StartService(timedIntent);
}
}
}
解决方案
感谢@android 开发者的回答。
您可以使用ACTION_MY_PACKAGE_REPLACED操作:
您的应用程序的新版本已安装在现有版本之上。这只会发送到被替换的应用程序。它不包含任何附加数据;要接收它,只需为此操作使用意图过滤器。
推荐阅读
- python-3.x - 如何合并位于两个不同文件夹中的多个文本文件并在 python 中的组合文件中创建一个新列?
- perl - 制作一次性引导脚本
- python - 调用函数时如何修复“标识符中的无效字符”
- laravel - 找不到我的页面,有人可以帮我吗?
- java - 通过 JoranConfigurator 加载 logback-spring.xml 时未读取 springProfile
- git - 将更改和添加的文件从没有工作树的裸仓库导出到目录以进行编译或部署
- r - 如何使用 lappy 进行字符串替换
- node.js - NodeJS 和 ReactJS 的 Heroku 部署
- javascript - 如何让窗口 onunload 事件触发器在 Chrome v73.x 中工作?
- r - 对于具有 dplyr 的其他两个变量的每个唯一组合,仅对分组数据框中的变量求和一次