When the data is purged, action_package_data_cleared broadcasts are sent, and the broadcast is monitored and processed in the Widgetprovider.
public static class Packagedataclearedreceiver extends Broadcastreceiver {private static final String Action_pack age_data_cleared = "Com.mediatek.intent.action.SETTINGS_PACKAGE_DATA_CLEARED"; public void OnReceive (context context, Intent Intent) {if (! Action_package_data_cleared.equals (Intent.getaction ())) {return; } String pkgname = Intent.getstringextra ("PackageName"); MUSICLOGUTILS.V (TAG, "packagedataclearedreceiver recevied pkgname =" + Pkgname); if (pkgname! = null && pkgname.equals (Context.getpackagename ())) {Mediaappwidgetprovider MEDIAAPPW Idgetprovider = Mediaappwidgetprovider. getinstance (); if (Mediaappwidgetprovider = = null) {MUSICLOGUTILS.V (TAG, "Mediaappwidgetprovider is null"); Return } mediaappwidgetprovider.defaultappwidget (context, NULL); } } }
The Defaultappwidget () function reloads the widget information and layout files so that the default values can be restored.
Finally, don't forget to add the androidmanefest.xml inside:
<receiver android:name= "Com.android.music.mediaappwidgetprovider$packagedataclearedreceiver" > < intent-filter> <action android:name= "Com.mediatek.intent.action.SETTINGS_PACKAGE_DATA_CLEARED"/> <category android:name= "Android.intent.category.DEFAULT"/> </intent-filter> </ Receiver>
Widget cannot update issue modification after Android clears data