gpt4 book ai didi

android - 每次在三星设备上更新应用程序时小部件都会消失

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:41:57 25 4
gpt4 key购买 nike

我的应用程序中有 2 个小部件。两者具有完全相同的功能,但布局不同。它们在每台设备上都运行良好,但在三星设备上似乎存在问题。每次我发布新版本的应用程序时,小部件都会从用户屏幕上删除。看起来这是一个 Samsung TouchWiz 错误,但用户告诉我其他应用程序没有这个问题。知道发生了什么事吗?

顺便说一句,我想了一下,我在这篇博文中找到了修复它的方法:https://medium.com/the-wtf-files/the-mysterious-case-of-the-disappearing-widget-f4177a8e2c2b但我没有手动调用

updateIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);

我调用

ComponentName cn = new ComponentName(context, clazz); AppWidgetManager.getInstance(context).updateAppWidget(cn, views);

为了更新我的小部件

更多我的代码:

    public static final int layout = R.layout.widget_large_layout;
public static final BitmapQualityEnum thumbnailQuality = BitmapQualityEnum.HIGH_RES;
public static final Class<?> clazz = LargeWidgetProvider.class;

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
if (context != null && appWidgetIds != null && appWidgetIds.length > 0) {
// To prevent any ANR timeouts, we perform the update in a service
context.startService( new Intent(context, LargeWidgetProvider.UpdateService.class));
}
}


@Override
public void onReceive(Context context, Intent intent) {
if (context != null && intent != null) {
boolean doUpdate = true;
if ("android.appwidget.action.APPWIDGET_UPDATE".equals(intent.getAction())) {
final int[] widgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
doUpdate = (widgetIds != null && widgetIds.length > 0);
}

if (doUpdate) {
WidgetProviderHelper.receive(context, intent, clazz, layout, thumbnailQuality);
}
super.onReceive(context, intent);
}
}

public static class UpdateService extends Service {

private int serviceStartId = -1;

@Override
public boolean onUnbind(Intent intent) {
stopSelf(this.serviceStartId);
return true;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.serviceStartId = startId;
// Push update for this widget to the home screen
updateData(this);
return START_STICKY;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// int oldOrientation = this.getResources().getConfiguration().orientation;
// if (newConfig.orientation != oldOrientation) {
// Update the widget) {
updateData(this);
// }
}


@Override
public IBinder onBind(Intent intent) {
// We don't need to bind to this service
return null;
}
}

最佳答案

我终于设法解决了我的问题。小部件提供者接收器需要导出!!

    <receiver
android:name=".widget.HorizontalWidgetProvider"
android:exported="true" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.customEvent" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_horizontal_provider" />
</receiver>

关于android - 每次在三星设备上更新应用程序时小部件都会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24091148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com