Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image in Widget

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

like image 601
Akhil Jain Avatar asked May 02 '13 16:05

Akhil Jain


1 Answers

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.

like image 166
Dan Riza Avatar answered Sep 28 '22 19:09

Dan Riza