【问题标题】:Xamarin Android BootReceiver Checking PackageXamarin Android BootReceiver 检查包
【发布时间】:2018-06-17 09:14:35
【问题描述】:

当我自己的包安装/更新时,我尝试执行 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);
        }
    }
}

【问题讨论】:

  • the called reason is because of the package the code is in,你是什么意思?您想使用BootReceiver 检查软件包安装/更新吗?或者您想使用BootReceiver 接收已安装/更新的软件包?
  • 现在,每当应用程序(任何应用程序)被替换/更新时,BroadcastReceiver 都会被调用——我想以某种方式只在 my 应用程序完成该操作时才调用它——也就是具有此代码的应用程序。
  • 你好,试试这个action,而不是ActionPackageReplaced
  • 嗨,你测试过我的答案吗?
  • 您好-抱歉,我正在测试手机时遇到了小问题。该应用程序的通知被阻止,现在我看不到通知(服务可能甚至没有启动)。一旦我找到一种无需重置手机即可修复它的方法,我就会尝试一下。还有一种方法可以在不需要实际更换的情况下对其进行测试吗?在 android 开发业务中相当新,在弄清楚所有测试工具之前我还有一段距离。

标签: c# android xamarin filter


【解决方案1】:

感谢@android 开发者的answer

您可以使用ACTION_MY_PACKAGE_REPLACED 操作:

您的应用程序的新版本已安装在现有版本之上。这只会发送到被替换的应用程序。它不包含任何附加数据;要接收它,只需为此操作使用意图过滤器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-21
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多