1

내가 구글 "StackWidget"샘플을 기반으로 내 안드로이드 응용 프로그램에 대한 간단한 위젯 개발하고 있어요에 URL에서 이미지로드 : https://android.googlesource.com/platform/development/+/master/samples/StackWidget/src/com/example/android/stackwidget/StackWidgetService.java위젯 - 원격보기

내가 글라이드 이미지 라이브러리를 사용하고 있는데 내가 채울려고을 RemoteViewsService를 확장 한 StackWidgetService 클래스의 getViewAt 메서드에 대한 ImageView. 나는 이런 일을하고 있어요 그러나 그것은 작동하지 않습니다 :

Handler uiHandler = new Handler(Looper.getMainLooper()); 
    uiHandler.post(() -> 
      Glide.with(context) 
      .asBitmap() 
      .load(widgetItems.get(position).image_url) 
      .into(new SimpleTarget<Bitmap>(512, 512) { 
       @Override 
       public void onResourceReady(Bitmap bitmap, Transition transition) { 
        rv.setImageViewBitmap(R.id.widget_item_image, bitmap); 
       } 
      })); 

안드로이드 위젯에서 리모트 뷰를 채울 수있는 URL에서 이미지로드의 정확하고 가장 좋은 방법은 무엇입니까?

+1

비동기 적으로 ('onResourceReady()')하지 마십시오. 'RemoteViews'를 리턴하면, 그것들은 완전히 채워 져야합니다. – CommonsWare

답변

0

동 기적으로 처리해야합니다. 이것은 정상적으로 작동하는 것 같습니다 :

try { 
     Bitmap bitmap = Glide.with(context) 
       .asBitmap() 
       .load(widgetItems.get(position).image_url) 
       .submit(512, 512) 
       .get(); 

     rv.setImageViewBitmap(R.id.widget_item_image, bitmap); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    }