Je suis nouveau sur le développement Android.Android - Je ne peux pas rendre un widget cliquable pour lancer une intention
J'ai développé un widget très simple qui était destiné à interagir avec l'utilisateur via un ImageButton. Ce que j'essaie de faire est maintenant comme suit. Lorsqu'un utilisateur appuie sur le bouton (après avoir ajouté le widget à son écran d'accueil), je souhaite que le téléphone compose un certain numéro de téléphone. Une sorte de numérotation abrégée pour votre écran d'accueil. Malheureusement, lorsque je tape sur le bouton, rien ne se passe.
Ceci est le corps de ma méthode de 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");
Je peux voir la méthode est appelée et le résultat de l'exploitation forestière est logique.
Le fichier speed_dial_appwidget.xml est comme ceci:
<?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>
Pouvez-vous s'il vous plaît me aider?
Merci à l'avance, Dan
Merci pour votre réponse.
Votre point était valide. J'ai ensuite ajouté ceci à mon manifeste:
<uses-permission android:name="android.permission.CALL_PHONE" />
Mais cela n'a pas aidé.
Les seules erreurs que je reçois sont:
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)
La chose étrange est: même avant d'ajouter l'étiquette des utilisations-permission, je ne vois pas de message d'erreur de ne pas avoir la permission suffisante.
Je ne comprends pas.
Avez-vous eu de la chance avec ce Daniele, je reçois la même erreur aujourd'hui –