【问题标题】:Intent action when data is cleared for Google Play Services为 Google Play 服务清除数据时的意图操作
【发布时间】:2019-01-07 08:59:46
【问题描述】:

我想在 Google Play 服务数据被清除时收到通知。

那么,有没有可以监听的 Intent 过滤器?

我想收听此事件,以便我可以重新注册地理围栏。 https://developer.android.com/training/location/geofencing

【问题讨论】:

    标签: android android-intent android-geofence


    【解决方案1】:

    这可以通过android.intent.action.PACKAGE_DATA_CLEARED 意图实现。

    将接收者添加到AndroidManifest.xml,就像您对任何意图一样:

    <receiver
        android:name=".DataClearedReceiver">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>
    

    您现在可以在DataClearedReceiver 中使用:

    override fun onReceive(context: Context, intent: Intent) {
        if (Intent.ACTION_PACKAGE_DATA_CLEARED.equals(intent.getAction()) && intent.getData() != null) {
            if (data.getSchemeSpecificPart() == "com.google.android.gms") {
               // perform action
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多