清除Google Play服务数据时的意图操作

时间:2019-01-07 08:59:47

标签: android android-intent android-geofence

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

那么,有没有任何意图过滤器来监听?

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

1 个答案:

答案 0 :(得分:0)

这可能是出于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
        }
    }
}