3

I'm trying to create a live wallpaper that reacts to clicking a button on a widget. According to this How to build a Simple Android Widget I'm overriding onStartCommand in my WallpaperService class but it seems that it's not called. Here is my code:

public class Wallpaper extends WallpaperService {
    WallpaperEngine engine;
    @Override
    public Engine onCreateEngine() {
        Log.d("Starting","Engine");
        engine = new WallpaperEngine();
        return engine;
    }

    @Override
    public int onStartCommand(Intent intent,  int flags, int startId){
        Log.d("Starting","command");
        engine.actions(intent);
        stopSelf(startId);
        return START_STICKY;
    }
    private class WallpaperEngine extends Engine{...}

Widget:

public class InteractionWidget extends AppWidgetProvider {
    private static final String FEED = "FeedAction";

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        // There may be multiple widgets active, so update all of them
        final int N = appWidgetIds.length;
        for (int i = 0; i < N; i++) {
            RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.interaction_widget);
            Intent intent = new Intent(context,Wallpaper.class);
            intent.setAction(FEED);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,appWidgetIds[i]);
            PendingIntent pendingIntent = PendingIntent.getService(context,0,intent,0);
            views.setOnClickPendingIntent(R.id.feedButton, pendingIntent);
            appWidgetManager.updateAppWidget(appWidgetIds[i],views);


            updateAppWidget(context, appWidgetManager, appWidgetIds[i]);
        }
    }

    @Override
    public void onEnabled(Context context) {
        // Enter relevant functionality for when the first widget is created
    }

    public void onReceive(Context context,Intent intent){
        if(FEED.equals(intent.getAction())){

        }
    }
    @Override
    public void onDisabled(Context context) {
        // Enter relevant functionality for when the last widget is disabled
    }

    static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                                int appWidgetId) {

        CharSequence widgetText = context.getString(R.string.appwidget_text);
        // Construct the RemoteViews object
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.interaction_widget);
        views.setTextViewText(R.id.appwidget_text, widgetText);

        // Instruct the widget manager to update the widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wallpaper.project.tamwallpaper" >

    <uses-feature
        android:name="android.software.live_wallpaper"
        android:required="true" >
    </uses-feature>



    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <service
            android:name=".Wallpaper"
            android:enabled="true"
            android:permission="android.permission.BIND_WALLPAPER" >
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" >
                </action>
            </intent-filter>

            <meta-data
                android:name="android.service.wallpaper"
                android:resource="@xml/wallpaper" >
            </meta-data>
        </service>

        <receiver android:name=".InteractionWidget" >
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>

            <meta-data
                android:name="android.appwidget.provider"
                android:resource="@xml/interaction_widget_info" />
        </receiver>
    </application>

</manifest>
Community
  • 1
  • 1
KrzysztofW
  • 57
  • 4
  • You have declared the Service and the App Widget Provider in the Manifest? – Plo_Koon Apr 15 '15 at 21:03
  • Yes, I have. I'm adding my manifest file to post. Wallpaper and widget are starting but I can't make widget to interact with wallpaper – KrzysztofW Apr 16 '15 at 09:21

0 Answers0