I am trying to set image in image view in widget layout in onUpdate, but 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 layout for 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>
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 try to load widget, i get a Toast "App isnt installed", I am not showing any such toast from where does it comes??
Why is image not setting, how to fix it??
Make sure you have the correct package name set in "android:configure" field in the appwidget-provider xml , and also you have the correct intetn-filter set in your manifest file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With