2010-05-23 60 views
0

我是Android开发的新手。Android - 我不能让一个widget点击来启动一个intent

我开发了一个非常简单的小部件,旨在通过ImageButton与用户进行交互。

我现在要做的是如下。当用户点击按钮时(在将小部件添加到他们的主屏幕之后),我希望手机拨打特定的电话号码。 您的主屏幕的一种快速拨号。

不幸的是,当我点击按钮什么也没有发生。

这是我SpeedDialAppWidgetProvider.onUpdate方法的主体:

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"); 

我可以看到被调用的方法和记录的结果是有道理的。

的speed_dial_appwidget.xml文件是这样的:

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

能否请你帮我这个?

由于提前, 丹


谢谢您的回答。

您的观点是有效的。然后我将其添加到我的清单中:

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

但这并没有帮助。

唯一的错误,我得到的是:

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) 

奇怪的是:即使添加了使用的许可标签之前,我没有看到你没有足够的权限的任何错误消息。

我不明白。

+0

你对这个丹妮尔有什么好运,今天我得到了同样的错误 – 2010-10-12 09:20:09

回答

0

ACTION_CALL需要特殊权限,您可能没有。 LogCat中应该有一个关于这个的警告 - 在Eclipse中使用adb logcat,DDMS或DDMS透视图来查看是否显示此警告。

您可能会考虑切换到ACTION_DIAL,而不需要特别许可,但它只是将电话号码放在拨号程序中,而不是实际拨打电话。

相关问题