7

Tôi cố gắng để thiết lập hình ảnh theo quan điểm hình ảnh trong cách bố trí widget trong onUpdate, nhưng hình ảnh không được cập nhậtHình ảnh trong Widget

@Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) 
    { 
     Log.i(TAG, "onUpdate called"); 
     for (int appWidgetId : appWidgetIds) 
     { 
      Bitmap bitmap=ImageUtils.getBitmap(context, appWidgetId); 
      RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget); 

      remoteView.setImageViewBitmap(R.id.imgView,bitmap); 
      appWidgetManager.updateAppWidget(appWidgetId, remoteView); 
     } 
    } 

layout xml cho widget

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imgView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

tập tin Manifest

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.demo.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".WidgetConfig" 
      android:label="@string/app_name" > 
      <intent-filter> 
        <action 
        android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> 
      </intent-filter> 
     </activity> 
     <receiver 
      android:name="BasicWidgetProvider"> 
      <intent-filter> 
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
      </intent-filter> 
      <meta-data 
       android:name="android.appwidget.provider" 
       android:resource="@xml/widget_info" /> 
     </receiver> 

      <receiver 
      android:name="BasicWidgetProvider"> 
      <intent-filter> 
       <action 
        android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
        <data android:scheme="widget" /> 
      </intent-filter> 
      <meta-data 
       android:name="android.appwidget.provider" 
       android:resource="@xml/widget_info" /> 
     </receiver> 
    </application> 

widget_info.xml

<appwidget-provider 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="25dp" 
    android:minHeight="25dp" 
    android:initialLayout="@layout/widget" 
    android:configure="com.demo.WidgetConfig" 
    android:widgetCategory="home_screen|keyguard" 
    android:previewImage="@layout/widget" 
    android:resizeMode="horizontal|vertical" 
    android:initialKeyguardLayout="@layout/widget" 
    android:minResizeHeight="5dp" 
    android:minResizeWidth="5dp"> 
</appwidget-provider> 

Nhưng khi cố gắng tải tiện ích, tôi nhận được một bánh mì nướng "App isnt cài đặt", tôi không hiển thị bất kỳ bánh mì nướng như vậy từ đâu đến ??

Tại sao hình ảnh không được đặt, cách khắc phục?

+0

Liệu nó load mà không ảnh? Đối với tôi, nó có vẻ như không đúng với tiện ích con/cấu hình ứng dụng không phải hình ảnh. Bạn có thể đăng tệp kê khai không? – Gustek

+0

tôi đã thêm tệp kê khai, xem mã –

Trả lời

1

Hãy chắc chắn rằng bạn có tên gói đúng thiết lập trong "android: cấu hình" trường trong xml appwidget-nhà cung cấp, và cũng có thể bạn có đúng intetn lọc đặt trong file manifest của bạn.

+0

xem mã được cập nhật –

+0

Ông cho biết nhà cung cấp tiện ích xml không phải là bố cục. – JoxTraex

+0

ok, tôi đã đăng cho nhận xét được đề cập và trả lời ở đây cũng vậy, thats ok của tôi xấu, một lần nữa cập nhật –

0

Vui lòng thử với remoteview.setimageViewuri như dưới đây.

@Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 

     remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); 
     thisWidget = new ComponentName(context, HelloWidget.class); 
     remoteViews.setImageViewUri(R.id.imageView1,Uri.parse("/mnt/sdcard/test.png")); 
     appWidgetManager.updateAppWidget(thisWidget, remoteViews); 
    } 
0
<receiver 
    android:name="BasicWidgetProvider"> 
    <intent-filter> 
     <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
    </intent-filter> 
    <meta-data 
     android:name="android.appwidget.provider" 
     android:resource="@xml/widget_info" /> 
</receiver> 

Bạn đang thiếu dấu chấm trước tên và Bạn có người nhận này hai lần.

0

Kiểm tra liên kết này.
Dưới đây là bản demo hoàn chỉnh cho phụ tùng Click Here và nhập khẩu này com.javatechig.widgetdemo dự án

+0

Lưu ý rằng [câu trả lời chỉ có liên kết được khuyến khích] (http://meta.stackoverflow.com/tags/link- chỉ-câu trả lời/thông tin), SO câu trả lời phải là điểm cuối của một tìm kiếm cho một giải pháp (so với một điểm dừng khác của tài liệu tham khảo, mà có xu hướng để có được cũ theo thời gian). Vui lòng xem xét thêm bản tóm tắt độc lập tại đây, giữ liên kết dưới dạng tham chiếu. – kleopatra