Image in widget

I am trying to set the image in the image view in the widget layout in onUpdate, but the image is not updating

@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); } } 

xml widget layout

 <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> 

Manifest file

 <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> 

But when I try to download the widget, I get Toast "the application is not installed ", I do not show such a toast, where does it come from?

Why the image is not installed, how to fix it ??

+7
source share
4 answers

Make sure that you have the correct package name set in the "android: configure" field in the appwidget-provider XML application, and that you have the correct set of intetn filters in your manifest file.

+1
source

Try using remoteview.setimageViewuri as shown below.

 @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
source
 <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> 

You are missing the dot in front of the name, and you have this receiver twice.

0
source

Check out this link.
Here is a complete demo for the widget. Click here and import this project com.javatechig.widgetdemo

0
source

All Articles