AppWidgetProvider problem

人盡茶涼 提交于 2019-11-30 15:47:25

You need to add android.appwidget.action.APPWIDGET_ENABLED as another action:

    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
    </intent-filter>

Without that, you will not receive the broadcast that triggers onEnabled().

GSD.Aaz

Don't forget about android:exported property! I didn't receive onDelete() when android:exported was false

<receiver 
    ...
    android:exported="true"
    ... >
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
        <action android:name="android.appwidget.action.APPWIDGET_DELETED" />
        <action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
        <action android:name="android.appwidget.action.APPWIDGET_DISABLED" />
    </intent-filter>

    <meta-data 
        android:name="android.appwidget.provider"
        android:resource=... />
</receiver>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!