tags:

views:

88

answers:

2

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

A: 

ACTION_CALL requires a special permission, which you may not have. There should be a warning in LogCat about this -- use adb logcat, DDMS, or the DDMS perspective in Eclipse to see if this warning shows up.

You might consider switching to ACTION_DIAL instead, which requires no special permission, though it just puts the phone number in the dialer rather than actually place the call.

CommonsWare
A: 

Thanks for your answer.

Your point was valid. I then added this to my manifest:

<uses-permission android:name="android.permission.CALL_PHONE" />

But that didn't help.

The only errors I get are:

05-23 18:41:08.932: ERROR/ActivityThread(655): Failed to find provider info for android.server.checkin
05-23 18:41:11.761: ERROR/ActivityThread(655): Failed to find provider info for android.server.checkin
05-23 18:41:14.372: ERROR/ActivityThread(655): Failed to find provider info for android.server.checkin
05-23 18:41:14.781: ERROR/ActivityThread(655): Failed to find provider info for android.server.checkin
05-23 18:41:43.892: ERROR/ActivityThread(676): Performing pause of activity that is not resumed: {com.android.launcher/com.android.launcher.Launcher}
05-23 18:41:43.892: ERROR/ActivityThread(676): java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.android.launcher/com.android.launcher.Launcher}
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2809)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2797)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2780)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.app.ActivityThread.access$2000(ActivityThread.java:112)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1699)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.os.Looper.loop(Looper.java:123)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at android.app.ActivityThread.main(ActivityThread.java:3948)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at java.lang.reflect.Method.invokeNative(Native Method)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at java.lang.reflect.Method.invoke(Method.java:521)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
05-23 18:41:43.892: ERROR/ActivityThread(676):     at dalvik.system.NativeStart.main(Native Method)

The strange thing is: even before adding the uses-permission tag, I didn't see any error message about not having enough permission.

I don't understand.

Daniele