Android - I can't make a widget clickable to launch an intent

Posted by Daniele on Stack Overflow See other posts from Stack Overflow or by Daniele
Published on 2010-05-23T21:48:32Z Indexed on 2010/05/23 21:50 UTC
Read the original article Hit count: 333

Filed under:

Hi all. I am new to Android development.

I have developed a very simple widget that was meant to interact with the user via an ImageButton.

What I am trying to do now is as follows. When a user taps the button (after adding the widget to their home screen), I want the phone to dial a certain telephone number. A sort of speed dial for your home screen.

Unfortunately when I tap the button nothing happens.

This is the body of my SpeedDialAppWidgetProvider.onUpdate method:

 Log.d("", "beginning of onUpdate");

 final int N = appWidgetIds.length;

    for (int i=0; i<N; i++) {
        int appWidgetId = appWidgetIds[i];

       Log.d("", "dealing with appWidgetId: " + appWidgetId);

        // Create an Intent to launch ExampleActivity
        Intent dialIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:1234567"));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, dialIntent, 0); 


       Log.d("", "pendingIntent classname " + pendingIntent.getClass().getName());

        // Get the layout for the App Widget and attach an on-click listener to the button
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.speed_dial_appwidget);
        remoteViews.setOnClickPendingIntent(R.id.dial_icon, pendingIntent); 

       Log.d("", "remoteViews classname " + remoteViews.getClass().getName());

        // Tell the AppWidgetManager to perform an update on the current App Widget
        appWidgetManager.updateAppWidget(appWidgetId, remoteViews);   

        Log.d("", "end of onUpdate");

I can see the method is called and the result of the logging makes sense.

The speed_dial_appwidget.xml file is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<ImageButton id="@+id/dial_icon"
android:src="@drawable/speed_dial"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/> 
</LinearLayout>

Can you please help me with this?

Thanks in advance, Dan

© Stack Overflow or respective owner

Related posts about android