0
위젯의 강제 사용자 정의 업데이트를 구현하려고합니다. 지금까지 알림이 수신되면 데이터가 읽히지 만 위젯을 데이터로 업데이트하려고하면 오류가 발생합니다. UI 스레드에서 picasso.load.into 함수를 사용해야한다고 나와 있습니다. 활동이없는 위젯에서 어떻게하면됩니까? 알림 서비스 안에 있습니까? 내 코드는 아래와 같습니다.NotificationExtenderService에서 캔트 업데이트 위젯 UI
NotificationServiceClass
는 picasso.load.into이 요구를 사용public class NotificationEx extends NotificationExtenderService {
private String l;
private String x;
@Override
protected boolean onNotificationProcessing(OSNotificationPayload notification) {
// Read properties from notification.
JSONObject jsonObject = notification.additionalData;
if (jsonObject.has("pic")) {
try {
l = jsonObject.getString("pic");
Log.e("treeN",l);
} catch (Exception e) {
Log.e("treeN",e.getMessage());
}
}
if (jsonObject.has("quote")) {
try {
x = jsonObject.getString("quote");
Log.e("treeN",x);
} catch (Exception e) {
Log.e("treeN",e.getMessage());
}
}
if (x!=null&&l!=null) {
/*MyApplication myApplication = new MyApplication();
myApplication.setPushedInfo(l,x);*/
setPushedInfo(l,x);
}
// Return true to stop the notifications from displaying.
return false;
}
public void setPushedInfo(String pic, String quote) {
RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.widget_home);
remoteViews.setTextViewText(R.id.widget_text, quote);
Picasso picasso = Picasso.with(this);
ComponentName thisWidget = new ComponentName(this, WidgetProvider.class);
int[] views = AppWidgetManager.getInstance(this).getAppWidgetIds(thisWidget);
picasso.load(pic)
.into(remoteViews, R.id.widget_background,views);
}
}