Jump to content

[AIDE] OnClick sur Widget


Recommended Posts

Bonjour, sa fait bientôt une semaine que je travaille à mettre un Widget clickable.
 
J'ai googlé, un max, lu le guide sur Android par Google, Stack OverFlow, des Blogs.... mais rien ne marche.
 
Ce n'est pas ma première application, en vrai c'est le portage de mon application en Widget.
 
Présentement je suis que dans le stade pour structure mes besoins;
- Rafraîchissement (servira a établir si mon lecteur est actif ou non et de changer l'image en conséquence) : J,arrive à changer mon image, alors la ici aucun problème.
- Capter le click sur le Widget, ou l'icone, pour permettre de démarrer ou arrêter mon lecteur : C'est ici que sa plante.
 
 
J'ai vu deux manière de créer un listener OnClick; dans le Layout XML ou dans le Activity JAVA.
 
En partant, je ne fait pas confiance au onclick dans le layout car un seul site en as parlé, et me semble désuet. Dans mes tentatives avec un Android virtuel (4.0.3) il plantait lorsque ce champs était défini.
 
Pour de l'autre, j'ai testé plusieurs manière, avec ou non la liste de tous les ID du appWidgetManager, inclure le Intent dans tous les appel qui réactualise l'affichage moindrement, j'ai également testé de moyen plus basic pour capturer les événement par étape.
 
J'ai commencer à inclure les Tags pour le LogCat, j'aurais du même m'y prendre dès le début, et je consulte le LogCat pour déterminé les actions. Mon Timer marche, et Android capte un Click sur mon application, le onReceiver capte le Update (une seul fois) et ne capte jamais les clicks.
 
Voici le code;

package com.levelkro.radiowidget;

import java.util.Timer;
import java.util.TimerTask;

import android.app.PendingIntent;
import android.appwidget.AppWidgetProvider;
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;


public class RadioWidget extends AppWidgetProvider {

	String Message = "Started";
	RemoteViews remoteViews;
	AppWidgetManager appWidgetManager;
	ComponentName thisWidget;	
	Timer timer = null;
	public static String ACT_CLICK = "CLICK";
	
	@[member=override]
	public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
		final int N = appWidgetIds.length;
		 for (int i=0; i<N; i++) {
	            int appWidgetId = appWidgetIds[i];
		
	            remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
	            thisWidget = new ComponentName(context, RadioWidget.class);
	            Intent intent = new Intent(context, RadioWidget.class);
	            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
	            intent.setAction(ACT_CLICK);
	            PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
	            
	            remoteViews.setOnClickPendingIntent(R.id.widget, pendingIntent);
	            context.sendBroadcast(intent);
	            appWidgetManager.updateAppWidget(thisWidget, remoteViews);
	            Log.d("DEBUG", "Start Widget " + appWidgetId);
		 }
		Timer timer = new Timer();
		timer.scheduleAtFixedRate(new radioUpdate(context, appWidgetManager, appWidgetIds), 1, 2000);
		Log.d("DEBUG", "Widget timer started");
	}
	
	@[member=override]
	public void onReceive(Context context, Intent intent) {
		super.onReceive(context, intent);
		Log.d(this.getClass().getName(), "OnReceive is called");    
	 	if (intent.getAction() == ACT_CLICK) {
		 	Message = "Clicked";
		 	Log.d("DEBUG-CLICK", "You click the Widget ? " + intent.getAction());
	 	}
	 	else if (intent.getAction() == "android.appwidget.action.APPWIDGET_UPDATE") {
	 		// DO nothing
	 	}
	 	else if (intent.getAction() == "android.appwidget.action.APPWIDGET_DELETED" || intent.getAction() == "android.appwidget.action.APPWIDGET_DISABLED") {
	 		// Is removed from home screen
	 		if (null != timer) {
	 	        timer.cancel();
	 	        Log.d("DEBUG","Closing; stopping " + timer.purge() + " timers");
	 	        timer = null;
	 	    }	 		
	 	}
	 	else {
	 		Message = "Unknow command";
	 		Log.d("DEBUG-CLICK", "Other action not monitored : " + intent.getAction().toString());
	 	}
	}
	public void mediaUpdate() {
		Log.d("DEBUG-CLICK", "Good, run the player");	
		
	}
	class radioUpdate extends TimerTask {
		AppWidgetManager appWidgetManager;

		public radioUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
			this.appWidgetManager = appWidgetManager;
	        Log.d("DEBUG", "Widget created");

		}		
		public void run() {
ssage);
			remoteViews.setImageViewResource(R.id.widget,R.drawable.ic_error);
			appWidgetManager.updateAppWidget(thisWidget, remoteViews);
			Log.d("DEBUG", "Class TimerTask run");
		}
	}
}

La ligne qui me fait comprendre que Android capte le Click ce trouve dans le main Logcat;

ActivityManager : START {act=CLICK flg=0x10000000 cmp=com.levelkro.radiowidget/.RadioWidget bnds=[88,226][152,289] (has extras)} from pid -1

Et voici un log complet du démarrage de l'application et d'un click manuel;

08-21 17:47:57.409: I/ActivityManager(82): Start proc com.levelkro.radiowidget for broadcast com.levelkro.radiowidget/.RadioWidget: pid=616 uid=10040 gids={3003}
08-21 17:47:57.690: D/com.levelkro.radiowidget.RadioWidget(616): OnReceive is called
08-21 17:47:57.719: D/StrictMode(593): StrictMode policy violation; ~duration=481 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=2967 violation=2
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1074)
08-21 17:47:57.719: D/StrictMode(593): 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:94)
08-21 17:47:57.719: D/StrictMode(593): 	at libcore.io.IoBridge.open(IoBridge.java:390)
08-21 17:47:57.719: D/StrictMode(593): 	at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
08-21 17:47:57.719: D/StrictMode(593): 	at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.os.AtomicFile.startWrite(AtomicFile.java:59)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1181)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.server.AppWidgetService.allocateAppWidgetId(AppWidgetService.java:335)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:79)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Binder.execTransact(Binder.java:338)
08-21 17:47:57.719: D/StrictMode(593): 	at dalvik.system.NativeStart.run(Native Method)
08-21 17:47:57.719: D/StrictMode(593): # via Binder call with stack:
08-21 17:47:57.719: D/StrictMode(593): android.os.StrictMode$LogStackTrace
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Parcel.readException(Parcel.java:1278)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.allocateAppWidgetId(IAppWidgetService.java:346)
08-21 17:47:57.719: D/StrictMode(593): 	at android.appwidget.AppWidgetHost.allocateAppWidgetId(AppWidgetHost.java:165)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.launcher2.Launcher.addAppWidgetFromDrop(Launcher.java:1520)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.launcher2.Workspace$11.run(Workspace.java:2899)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.launcher2.DragLayer$3.onAnimationEnd(DragLayer.java:501)
08-21 17:47:57.719: D/StrictMode(593): 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1033)
08-21 17:47:57.719: D/StrictMode(593): 	at android.animation.ValueAnimator.access$900(ValueAnimator.java:42)
08-21 17:47:57.719: D/StrictMode(593): 	at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:668)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Looper.loop(Looper.java:137)
08-21 17:47:57.719: D/StrictMode(593): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-21 17:47:57.719: D/StrictMode(593): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-21 17:47:57.719: D/StrictMode(593): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 17:47:57.719: D/StrictMode(593): 	at dalvik.system.NativeStart.main(Native Method)
08-21 17:47:57.719: D/StrictMode(593): StrictMode policy violation; ~duration=473 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2967 violation=1
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
08-21 17:47:57.719: D/StrictMode(593): 	at libcore.io.BlockGuardOs.write(BlockGuardOs.java:178)
08-21 17:47:57.719: D/StrictMode(593): 	at libcore.io.IoBridge.write(IoBridge.java:447)
08-21 17:47:57.719: D/StrictMode(593): 	at java.io.FileOutputStream.write(FileOutputStream.java:187)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:212)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:233)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.server.AppWidgetService.writeStateToFileLocked(AppWidgetService.java:1240)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1182)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.server.AppWidgetService.allocateAppWidgetId(AppWidgetService.java:335)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:79)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Binder.execTransact(Binder.java:338)
08-21 17:47:57.719: D/StrictMode(593): 	at dalvik.system.NativeStart.run(Native Method)
08-21 17:47:57.719: D/StrictMode(593): # via Binder call with stack:
08-21 17:47:57.719: D/StrictMode(593): android.os.StrictMode$LogStackTrace
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Parcel.readException(Parcel.java:1278)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.allocateAppWidgetId(IAppWidgetService.java:346)
08-21 17:47:57.719: D/StrictMode(593): 	at android.appwidget.AppWidgetHost.allocateAppWidgetId(AppWidgetHost.java:165)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.launcher2.Launcher.addAppWidgetFromDrop(Launcher.java:1520)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.launcher2.Workspace$11.run(Workspace.java:2899)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.launcher2.DragLayer$3.onAnimationEnd(DragLayer.java:501)
08-21 17:47:57.719: D/StrictMode(593): 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1033)
08-21 17:47:57.719: D/StrictMode(593): 	at android.animation.ValueAnimator.access$900(ValueAnimator.java:42)
08-21 17:47:57.719: D/StrictMode(593): 	at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:668)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 17:47:57.719: D/StrictMode(593): 	at android.os.Looper.loop(Looper.java:137)
08-21 17:47:57.719: D/StrictMode(593): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-21 17:47:57.719: D/StrictMode(593): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-21 17:47:57.719: D/StrictMode(593): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 17:47:57.719: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 17:47:57.719: D/StrictMode(593): 	at dalvik.system.NativeStart.main(Native Method)
08-21 17:47:57.740: D/DEBUG-CLICK(616): Other action not monitored : android.appwidget.action.APPWIDGET_ENABLED
08-21 17:47:57.769: D/StrictMode(593): StrictMode policy violation; ~duration=448 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2967 violation=1
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
08-21 17:47:57.769: D/StrictMode(593): 	at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:84)
08-21 17:47:57.769: D/StrictMode(593): 	at java.io.FileDescriptor.sync(FileDescriptor.java:71)
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.FileUtils.sync(FileUtils.java:111)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.internal.os.AtomicFile.finishWrite(AtomicFile.java:80)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1183)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.server.AppWidgetService.allocateAppWidgetId(AppWidgetService.java:335)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:79)
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.Binder.execTransact(Binder.java:338)
08-21 17:47:57.769: D/StrictMode(593): 	at dalvik.system.NativeStart.run(Native Method)
08-21 17:47:57.769: D/StrictMode(593): # via Binder call with stack:
08-21 17:47:57.769: D/StrictMode(593): android.os.StrictMode$LogStackTrace
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.Parcel.readException(Parcel.java:1278)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.allocateAppWidgetId(IAppWidgetService.java:346)
08-21 17:47:57.769: D/StrictMode(593): 	at android.appwidget.AppWidgetHost.allocateAppWidgetId(AppWidgetHost.java:165)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.launcher2.Launcher.addAppWidgetFromDrop(Launcher.java:1520)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.launcher2.Workspace$11.run(Workspace.java:2899)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.launcher2.DragLayer$3.onAnimationEnd(DragLayer.java:501)
08-21 17:47:57.769: D/StrictMode(593): 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1033)
08-21 17:47:57.769: D/StrictMode(593): 	at android.animation.ValueAnimator.access$900(ValueAnimator.java:42)
08-21 17:47:57.769: D/StrictMode(593): 	at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:668)
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 17:47:57.769: D/StrictMode(593): 	at android.os.Looper.loop(Looper.java:137)
08-21 17:47:57.769: D/StrictMode(593): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-21 17:47:57.769: D/StrictMode(593): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-21 17:47:57.769: D/StrictMode(593): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 17:47:57.769: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 17:47:57.769: D/StrictMode(593): 	at dalvik.system.NativeStart.main(Native Method)
08-21 17:47:57.819: D/StrictMode(593): StrictMode policy violation; ~duration=364 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=2967 violation=2
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1074)
08-21 17:47:57.819: D/StrictMode(593): 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:94)
08-21 17:47:57.819: D/StrictMode(593): 	at libcore.io.IoBridge.open(IoBridge.java:390)
08-21 17:47:57.819: D/StrictMode(593): 	at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
08-21 17:47:57.819: D/StrictMode(593): 	at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.internal.os.AtomicFile.startWrite(AtomicFile.java:59)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1181)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.server.AppWidgetService.bindAppWidgetId(AppWidgetService.java:482)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:225)
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.Binder.execTransact(Binder.java:338)
08-21 17:47:57.819: D/StrictMode(593): 	at dalvik.system.NativeStart.run(Native Method)
08-21 17:47:57.819: D/StrictMode(593): # via Binder call with stack:
08-21 17:47:57.819: D/StrictMode(593): android.os.StrictMode$LogStackTrace
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.Parcel.readException(Parcel.java:1278)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.bindAppWidgetId(IAppWidgetService.java:569)
08-21 17:47:57.819: D/StrictMode(593): 	at android.appwidget.AppWidgetManager.bindAppWidgetId(AppWidgetManager.java:432)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.launcher2.Launcher.addAppWidgetFromDrop(Launcher.java:1521)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.launcher2.Workspace$11.run(Workspace.java:2899)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.launcher2.DragLayer$3.onAnimationEnd(DragLayer.java:501)
08-21 17:47:57.819: D/StrictMode(593): 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1033)
08-21 17:47:57.819: D/StrictMode(593): 	at android.animation.ValueAnimator.access$900(ValueAnimator.java:42)
08-21 17:47:57.819: D/StrictMode(593): 	at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:668)
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 17:47:57.819: D/StrictMode(593): 	at android.os.Looper.loop(Looper.java:137)
08-21 17:47:57.819: D/StrictMode(593): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-21 17:47:57.819: D/StrictMode(593): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-21 17:47:57.819: D/StrictMode(593): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 17:47:57.819: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 17:47:57.819: D/StrictMode(593): 	at dalvik.system.NativeStart.main(Native Method)
08-21 17:47:57.839: D/StrictMode(593): StrictMode policy violation; ~duration=333 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2967 violation=1
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
08-21 17:47:57.839: D/StrictMode(593): 	at libcore.io.BlockGuardOs.write(BlockGuardOs.java:178)
08-21 17:47:57.839: D/StrictMode(593): 	at libcore.io.IoBridge.write(IoBridge.java:447)
08-21 17:47:57.839: D/StrictMode(593): 	at java.io.FileOutputStream.write(FileOutputStream.java:187)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:212)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:233)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.server.AppWidgetService.writeStateToFileLocked(AppWidgetService.java:1240)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1182)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.server.AppWidgetService.bindAppWidgetId(AppWidgetService.java:482)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:225)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Binder.execTransact(Binder.java:338)
08-21 17:47:57.839: D/StrictMode(593): 	at dalvik.system.NativeStart.run(Native Method)
08-21 17:47:57.839: D/StrictMode(593): # via Binder call with stack:
08-21 17:47:57.839: D/StrictMode(593): android.os.StrictMode$LogStackTrace
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Parcel.readException(Parcel.java:1278)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.bindAppWidgetId(IAppWidgetService.java:569)
08-21 17:47:57.839: D/StrictMode(593): 	at android.appwidget.AppWidgetManager.bindAppWidgetId(AppWidgetManager.java:432)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.launcher2.Launcher.addAppWidgetFromDrop(Launcher.java:1521)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.launcher2.Workspace$11.run(Workspace.java:2899)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.launcher2.DragLayer$3.onAnimationEnd(DragLayer.java:501)
08-21 17:47:57.839: D/StrictMode(593): 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1033)
08-21 17:47:57.839: D/StrictMode(593): 	at android.animation.ValueAnimator.access$900(ValueAnimator.java:42)
08-21 17:47:57.839: D/StrictMode(593): 	at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:668)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Looper.loop(Looper.java:137)
08-21 17:47:57.839: D/StrictMode(593): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-21 17:47:57.839: D/StrictMode(593): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-21 17:47:57.839: D/StrictMode(593): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 17:47:57.839: D/StrictMode(593): 	at dalvik.system.NativeStart.main(Native Method)
08-21 17:47:57.839: D/StrictMode(593): StrictMode policy violation; ~duration=301 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2967 violation=1
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
08-21 17:47:57.839: D/StrictMode(593): 	at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:84)
08-21 17:47:57.839: D/StrictMode(593): 	at java.io.FileDescriptor.sync(FileDescriptor.java:71)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.FileUtils.sync(FileUtils.java:111)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.os.AtomicFile.finishWrite(AtomicFile.java:80)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1183)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.server.AppWidgetService.bindAppWidgetId(AppWidgetService.java:482)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:225)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Binder.execTransact(Binder.java:338)
08-21 17:47:57.839: D/StrictMode(593): 	at dalvik.system.NativeStart.run(Native Method)
08-21 17:47:57.839: D/StrictMode(593): # via Binder call with stack:
08-21 17:47:57.839: D/StrictMode(593): android.os.StrictMode$LogStackTrace
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Parcel.readException(Parcel.java:1278)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.bindAppWidgetId(IAppWidgetService.java:569)
08-21 17:47:57.839: D/StrictMode(593): 	at android.appwidget.AppWidgetManager.bindAppWidgetId(AppWidgetManager.java:432)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.launcher2.Launcher.addAppWidgetFromDrop(Launcher.java:1521)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.launcher2.Workspace$11.run(Workspace.java:2899)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.launcher2.DragLayer$3.onAnimationEnd(DragLayer.java:501)
08-21 17:47:57.839: D/StrictMode(593): 	at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1033)
08-21 17:47:57.839: D/StrictMode(593): 	at android.animation.ValueAnimator.access$900(ValueAnimator.java:42)
08-21 17:47:57.839: D/StrictMode(593): 	at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:668)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 17:47:57.839: D/StrictMode(593): 	at android.os.Looper.loop(Looper.java:137)
08-21 17:47:57.839: D/StrictMode(593): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-21 17:47:57.839: D/StrictMode(593): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-21 17:47:57.839: D/StrictMode(593): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-21 17:47:57.839: D/StrictMode(593): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-21 17:47:57.839: D/StrictMode(593): 	at dalvik.system.NativeStart.main(Native Method)
08-21 17:47:57.899: D/DEBUG(616): Start Widget 68
08-21 17:47:57.920: D/DEBUG(616): Widget created
08-21 17:47:57.929: D/DEBUG(616): Class TimerTask run
08-21 17:47:57.929: D/DEBUG(616): Widget timer started
08-21 17:47:57.940: D/com.levelkro.radiowidget.RadioWidget(616): OnReceive is called
08-21 17:47:57.959: D/com.levelkro.radiowidget.RadioWidget(616): OnReceive is called
08-21 17:47:57.959: D/DEBUG-CLICK(616): You click the Widget ? CLICK
08-21 17:47:59.930: D/DEBUG(616): Class TimerTask run
08-21 17:48:00.180: D/dalvikvm(82): GC_CONCURRENT freed 468K, 9% free 9155K/10055K, paused 6ms+10ms
08-21 17:48:01.919: I/ActivityManager(82): START {act=CLICK flg=0x10000000 cmp=com.levelkro.radiowidget/.RadioWidget bnds=[168,326][232,389] (has extras)} from pid -1
08-21 17:48:01.929: D/DEBUG(616): Class TimerTask run

Avec ce log, ont voit qu'au démarrage, il ce click une fois lui même et que le onReceiver la capté (08-21 17:47:57.959: D/DEBUG-CLICK(616): You click the Widget ? CLICK).

 

Le ButtonImage a aussi été un TextView et un Image, j'ai aussi tenté de le faire directement sur le Layout, rien de plus.

 

Alors quoi faire pour fixer ce code et faire en sorte de répondre à un Click sur le Widget ? Merci de m'aider :)

 

* note : l'écriture en anglais est volontaire, je code toujours en anglais dans mon stade alpha/beta, sa me permet d'éliminer, peut importe le langage utilisé comme code, les troubles avec les accents et de poster rapidement sur les forums anglophones.

 

 

Link to comment
Share on other sites

Bonjour,

 

Le problème vient probablement de la façon de créer le PendingIntent. Tu crées un PendingIntent qui va essayer de lancer une Activity, ce que RadioWidget (la classe avec laquelle tu as initialisé l'Intent) n'est pas.

Remplace

PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, 0);
par
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, appWidgetId, intent, 0);
et reviens nous dire si ça marche mieux ;)
Link to comment
Share on other sites

Merci, en effet ça marche...

J'ai jamais vus de réponse souligner ce problème et j'ai moi même jamais remarquer si il y avais une différence à ce niveau de la commande, malgré que j'ai changé, par test, certain valeurs.

 

Bon maintenant je doit fixer le Timer, j'essai quelques trucs actuellement car la commande ne marche pas. Je connais malheureusement pas assez le Java :/, j'apprend avec les tutoriaux et forums.

Link to comment
Share on other sites

08-23 03:37:51.734: D/DEBUG(753): Start Widget 74
08-23 03:37:51.744: D/DEBUG(753): Widget timer started
08-23 03:37:51.754: D/DEBUG(753): Widget click by user
08-23 03:37:51.754: D/MediaPlayer(753): Couldn't open file on client side, trying server side
08-23 03:37:51.824: I/AwesomePlayer(37): setDataSource_l('http://69.163.34.200:8000/1/listen.mp3')
08-23 03:37:51.854: W/WindowManager(93): Failure taking screenshot for (230x383) to layer 21015
08-23 03:37:51.874: V/ChromiumHTTPDataSource(37): connect on behalf of uid 10040
08-23 03:37:51.874: I/ChromiumHTTPDataSource(37): connect to http://69.163.34.200:8000/1/listen.mp3 @0
08-23 03:37:51.884: I/qtaguid(37): Tagging socket 27 with tag 3f500000000(1013) for uid 10040 failed errno=-2
08-23 03:37:51.974: D/StrictMode(213): StrictMode policy violation; ~duration=372 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=2967 violation=2
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1074)
08-23 03:37:51.974: D/StrictMode(213): 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:94)
08-23 03:37:51.974: D/StrictMode(213): 	at libcore.io.IoBridge.open(IoBridge.java:390)
08-23 03:37:51.974: D/StrictMode(213): 	at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
08-23 03:37:51.974: D/StrictMode(213): 	at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.os.AtomicFile.startWrite(AtomicFile.java:59)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1181)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.server.AppWidgetService.bindAppWidgetId(AppWidgetService.java:482)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:225)
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.Binder.execTransact(Binder.java:338)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.server.SystemServer.init1(Native Method)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.server.SystemServer.main(SystemServer.java:808)
08-23 03:37:51.974: D/StrictMode(213): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-23 03:37:51.974: D/StrictMode(213): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 03:37:51.974: D/StrictMode(213): 	at dalvik.system.NativeStart.main(Native Method)
08-23 03:37:51.974: D/StrictMode(213): # via Binder call with stack:
08-23 03:37:51.974: D/StrictMode(213): android.os.StrictMode$LogStackTrace
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.Parcel.readException(Parcel.java:1278)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.bindAppWidgetId(IAppWidgetService.java:569)
08-23 03:37:51.974: D/StrictMode(213): 	at android.appwidget.AppWidgetManager.bindAppWidgetId(AppWidgetManager.java:432)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.settings.AppWidgetPickActivity.onClick(AppWidgetPickActivity.java:149)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
08-23 03:37:51.974: D/StrictMode(213): 	at android.widget.AdapterView.performItemClick(AdapterView.java:292)
08-23 03:37:51.974: D/StrictMode(213): 	at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
08-23 03:37:51.974: D/StrictMode(213): 	at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
08-23 03:37:51.974: D/StrictMode(213): 	at android.widget.AbsListView$1.run(AbsListView.java:3168)
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.Handler.handleCallback(Handler.java:605)
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.Handler.dispatchMessage(Handler.java:92)
08-23 03:37:51.974: D/StrictMode(213): 	at android.os.Looper.loop(Looper.java:137)
08-23 03:37:51.974: D/StrictMode(213): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-23 03:37:51.974: D/StrictMode(213): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-23 03:37:51.974: D/StrictMode(213): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 03:37:51.974: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 03:37:51.974: D/StrictMode(213): 	at dalvik.system.NativeStart.main(Native Method)
08-23 03:37:52.004: D/StrictMode(213): StrictMode policy violation; ~duration=288 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2967 violation=1
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
08-23 03:37:52.004: D/StrictMode(213): 	at libcore.io.BlockGuardOs.write(BlockGuardOs.java:178)
08-23 03:37:52.004: D/StrictMode(213): 	at libcore.io.IoBridge.write(IoBridge.java:447)
08-23 03:37:52.004: D/StrictMode(213): 	at java.io.FileOutputStream.write(FileOutputStream.java:187)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.util.FastXmlSerializer.flushBytes(FastXmlSerializer.java:212)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.util.FastXmlSerializer.flush(FastXmlSerializer.java:233)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.util.FastXmlSerializer.endDocument(FastXmlSerializer.java:183)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.server.AppWidgetService.writeStateToFileLocked(AppWidgetService.java:1240)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1182)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.server.AppWidgetService.bindAppWidgetId(AppWidgetService.java:482)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:225)
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.Binder.execTransact(Binder.java:338)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.server.SystemServer.init1(Native Method)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.server.SystemServer.main(SystemServer.java:808)
08-23 03:37:52.004: D/StrictMode(213): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-23 03:37:52.004: D/StrictMode(213): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 03:37:52.004: D/StrictMode(213): 	at dalvik.system.NativeStart.main(Native Method)
08-23 03:37:52.004: D/StrictMode(213): # via Binder call with stack:
08-23 03:37:52.004: D/StrictMode(213): android.os.StrictMode$LogStackTrace
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.Parcel.readException(Parcel.java:1278)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.bindAppWidgetId(IAppWidgetService.java:569)
08-23 03:37:52.004: D/StrictMode(213): 	at android.appwidget.AppWidgetManager.bindAppWidgetId(AppWidgetManager.java:432)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.settings.AppWidgetPickActivity.onClick(AppWidgetPickActivity.java:149)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
08-23 03:37:52.004: D/StrictMode(213): 	at android.widget.AdapterView.performItemClick(AdapterView.java:292)
08-23 03:37:52.004: D/StrictMode(213): 	at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
08-23 03:37:52.004: D/StrictMode(213): 	at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
08-23 03:37:52.004: D/StrictMode(213): 	at android.widget.AbsListView$1.run(AbsListView.java:3168)
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.Handler.handleCallback(Handler.java:605)
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.Handler.dispatchMessage(Handler.java:92)
08-23 03:37:52.004: D/StrictMode(213): 	at android.os.Looper.loop(Looper.java:137)
08-23 03:37:52.004: D/StrictMode(213): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-23 03:37:52.004: D/StrictMode(213): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-23 03:37:52.004: D/StrictMode(213): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 03:37:52.004: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 03:37:52.004: D/StrictMode(213): 	at dalvik.system.NativeStart.main(Native Method)
08-23 03:37:52.034: D/StrictMode(213): StrictMode policy violation; ~duration=283 ms: android.os.StrictMode$StrictModeDiskWriteViolation: policy=2967 violation=1
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onWriteToDisk(StrictMode.java:1048)
08-23 03:37:52.034: D/StrictMode(213): 	at libcore.io.BlockGuardOs.fsync(BlockGuardOs.java:84)
08-23 03:37:52.034: D/StrictMode(213): 	at java.io.FileDescriptor.sync(FileDescriptor.java:71)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.FileUtils.sync(FileUtils.java:111)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.os.AtomicFile.finishWrite(AtomicFile.java:80)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.server.AppWidgetService.saveStateLocked(AppWidgetService.java:1183)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.server.AppWidgetService.bindAppWidgetId(AppWidgetService.java:482)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.appwidget.IAppWidgetService$Stub.onTransact(IAppWidgetService.java:225)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.Binder.execTransact(Binder.java:338)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.server.SystemServer.init1(Native Method)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.server.SystemServer.main(SystemServer.java:808)
08-23 03:37:52.034: D/StrictMode(213): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-23 03:37:52.034: D/StrictMode(213): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 03:37:52.034: D/StrictMode(213): 	at dalvik.system.NativeStart.main(Native Method)
08-23 03:37:52.034: D/StrictMode(213): # via Binder call with stack:
08-23 03:37:52.034: D/StrictMode(213): android.os.StrictMode$LogStackTrace
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.StrictMode.readAndHandleBinderCallViolations(StrictMode.java:1602)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.Parcel.readExceptionCode(Parcel.java:1309)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.Parcel.readException(Parcel.java:1278)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.bindAppWidgetId(IAppWidgetService.java:569)
08-23 03:37:52.034: D/StrictMode(213): 	at android.appwidget.AppWidgetManager.bindAppWidgetId(AppWidgetManager.java:432)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.settings.AppWidgetPickActivity.onClick(AppWidgetPickActivity.java:149)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:924)
08-23 03:37:52.034: D/StrictMode(213): 	at android.widget.AdapterView.performItemClick(AdapterView.java:292)
08-23 03:37:52.034: D/StrictMode(213): 	at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
08-23 03:37:52.034: D/StrictMode(213): 	at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)
08-23 03:37:52.034: D/StrictMode(213): 	at android.widget.AbsListView$1.run(AbsListView.java:3168)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.Handler.handleCallback(Handler.java:605)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.Handler.dispatchMessage(Handler.java:92)
08-23 03:37:52.034: D/StrictMode(213): 	at android.os.Looper.loop(Looper.java:137)
08-23 03:37:52.034: D/StrictMode(213): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
08-23 03:37:52.034: D/StrictMode(213): 	at java.lang.reflect.Method.invokeNative(Native Method)
08-23 03:37:52.034: D/StrictMode(213): 	at java.lang.reflect.Method.invoke(Method.java:511)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 03:37:52.034: D/StrictMode(213): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 03:37:52.034: D/StrictMode(213): 	at dalvik.system.NativeStart.main(Native Method)
08-23 03:37:52.565: W/InputManagerService(93): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@41317c08
08-23 03:37:52.614: D/dalvikvm(93): GC_CONCURRENT freed 538K, 12% free 9207K/10439K, paused 5ms+96ms
08-23 03:37:52.724: W/NetworkManagementSocketTagger(93): setKernelCountSet(1000, 0) failed with errno -2
08-23 03:37:57.834: D/dalvikvm(722): GC_CONCURRENT freed 253K, 5% free 7014K/7367K, paused 6ms+5ms
08-23 03:38:01.754: W/ActivityManager(93): Timeout of broadcast BroadcastRecord{4133f108 CLICK} - receiver=android.os.BinderProxy@4133cb40, started 10009ms ago
08-23 03:38:01.754: W/ActivityManager(93): Receiver during timeout: ResolveInfo{4133f080 com.levelkro.radiowidget.RadioWidget p=0 o=0 m=0x0}
08-23 03:38:01.804: I/Process(93): Sending signal. PID: 753 SIG: 3
08-23 03:38:01.804: I/dalvikvm(753): threadid=3: reacting to signal 3
08-23 03:38:01.824: I/dalvikvm(753): Wrote stack traces to '/data/anr/traces.txt'
08-23 03:38:01.841: I/Process(93): Sending signal. PID: 93 SIG: 3
08-23 03:38:01.841: I/dalvikvm(93): threadid=3: reacting to signal 3
08-23 03:38:02.006: I/dalvikvm(93): Wrote stack traces to '/data/anr/traces.txt'
08-23 03:38:02.028: I/Process(93): Sending signal. PID: 146 SIG: 3
08-23 03:38:02.028: I/dalvikvm(146): threadid=3: reacting to signal 3
08-23 03:38:02.044: I/dalvikvm(146): Wrote stack traces to '/data/anr/traces.txt'
08-23 03:38:02.044: I/Process(93): Sending signal. PID: 174 SIG: 3
08-23 03:38:02.044: I/dalvikvm(174): threadid=3: reacting to signal 3
08-23 03:38:02.085: I/dalvikvm(174): Wrote stack traces to '/data/anr/traces.txt'
08-23 03:38:02.664: D/dalvikvm(93): GC_CONCURRENT freed 510K, 11% free 9295K/10439K, paused 6ms+12ms
08-23 03:38:02.924: D/dalvikvm(93): GC_EXPLICIT freed 85K, 11% free 9305K/10439K, paused 7ms+11ms
08-23 03:38:03.514: I/Process(93): Sending signal. PID: 722 SIG: 3
08-23 03:38:03.514: I/dalvikvm(722): threadid=3: reacting to signal 3
08-23 03:38:03.524: I/dalvikvm(722): Wrote stack traces to '/data/anr/traces.txt'
08-23 03:38:03.554: E/ActivityManager(93): ANR in com.levelkro.radiowidget
08-23 03:38:03.554: E/ActivityManager(93): Reason: Broadcast of Intent { act=CLICK flg=0x10 cmp=com.levelkro.radiowidget/.RadioWidget (has extras) }
08-23 03:38:03.554: E/ActivityManager(93): Load: 0.04 / 0.01 / 0.09
08-23 03:38:03.554: E/ActivityManager(93): CPU usage from 8814ms to 1993ms ago:
08-23 03:38:03.554: E/ActivityManager(93):   2.4% 722/com.android.widgetpreview: 1.7% user + 0.7% kernel / faults: 829 minor
08-23 03:38:03.554: E/ActivityManager(93):   0.4% 93/system_server: 0.4% user + 0% kernel
08-23 03:38:03.554: E/ActivityManager(93):   0.1% 37/mediaserver: 0.1% user + 0% kernel / faults: 21 minor
08-23 03:38:03.554: E/ActivityManager(93):   0.1% 753/com.levelkro.radiowidget: 0% user + 0.1% kernel / faults: 28 minor
08-23 03:38:03.554: E/ActivityManager(93): 3.2% TOTAL: 2.3% user + 0.8% kernel
08-23 03:38:03.554: E/ActivityManager(93): CPU usage from 1152ms to 1699ms later:
08-23 03:38:03.554: E/ActivityManager(93):   9.2% 93/system_server: 3.7% user + 5.5% kernel
08-23 03:38:03.554: E/ActivityManager(93):     9.2% 108/ActivityManager: 1.8% user + 7.4% kernel
08-23 03:38:03.554: E/ActivityManager(93):     1.8% 93/system_server: 1.8% user + 0% kernel
08-23 03:38:03.554: E/ActivityManager(93):   1.3% 722/com.android.widgetpreview: 1.3% user + 0% kernel / faults: 3 minor
08-23 03:38:03.554: E/ActivityManager(93):     1.3% 722/d.widgetpreview: 1.3% user + 0% kernel
08-23 03:38:03.554: E/ActivityManager(93):     1.3% 733/Binder Thread #: 1.3% user + 0% kernel
08-23 03:38:03.554: E/ActivityManager(93): 12% TOTAL: 3.6% user + 9% kernel
08-23 03:38:03.554: W/ActivityManager(93): Killing ProcessRecord{411d2790 753:com.levelkro.radiowidget/10040}: background ANR
08-23 03:38:03.574: I/ActivityManager(93): Process com.levelkro.radiowidget (pid 753) has died.
08-23 03:38:03.574: D/StrictMode(93): StrictMode policy violation; ~duration=1776 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=151 violation=2
08-23 03:38:03.574: D/StrictMode(93): 	at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1074)
08-23 03:38:03.574: D/StrictMode(93): 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:94)
08-23 03:38:03.574: D/StrictMode(93): 	at java.io.File.createNewFile(File.java:933)
08-23 03:38:03.574: D/StrictMode(93): 	at com.android.server.am.ActivityManagerService.dumpStackTraces(ActivityManagerService.java:2851)
08-23 03:38:03.574: D/StrictMode(93): 	at com.android.server.am.ActivityManagerService.appNotResponding(ActivityManagerService.java:3017)
08-23 03:38:03.574: D/StrictMode(93): 	at com.android.server.am.ActivityManagerService$AppNotResponding.run(ActivityManagerService.java:2931)
08-23 03:38:03.574: D/StrictMode(93): 	at android.os.Handler.handleCallback(Handler.java:605)
08-23 03:38:03.574: D/StrictMode(93): 	at android.os.Handler.dispatchMessage(Handler.java:92)
08-23 03:38:03.574: D/StrictMode(93): 	at android.os.Looper.loop(Looper.java:137)
08-23 03:38:03.574: D/StrictMode(93): 	at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1364)
08-23 03:38:03.754: D/dalvikvm(93): GC_FOR_ALLOC freed 431K, 12% free 9267K/10439K, paused 113ms
08-23 03:38:03.775: I/AwesomePlayer(37): Prepare cancelled while waiting for initial cache fill.
08-23 03:38:07.005: I/qtaguid(37): Untagging socket 27 failed errno=-2
 

J'avais inclus mes commandes dans le OnReceiver, mais avec cette erreur j'ai tenté de le faire avec une autre commande (ctrlPlayer()), mais même résultat.

 

Merci de m'aider à me diriger vers la solution.

Bon nouveau problème.

 

Le Widget est conçu pour lire ma radio Internet (Type SHOUTCAST). J'ai une application qui marche, je sais que dès je demande au MediaPlayer de créer le Stream, j'ai un "freeze" pendant 5 à 25 secondes, soit le temps de rejoindre le serveur, négocier le démarrage du Streaming et de démarrer le stream après un buffer.

 

Cependant, ce que je ne savais pas, c'est que le Broadcast (onReceiver) possède un TImeout, soit 10 secondes, mais j'obtient une erreur bien avant ce délais atteint.

 

Mon idée serait de lancer une commande externe du onReceiver pour sortir de ce délais, cependant je doit avoir mon Context et une variable (savoir si ont démarre ou on stop la lecture).

 

Voici le code;

 

	@[member=override]
	public void onReceive(Context context, Intent intent) {
		super.onReceive(context, intent);
		//Log.d(this.getClass().getName(), "OnReceive is called");    
	 	if (intent.getAction() == "CLICK" && GlobalRadio.getClickState() == "READY") {
		 	Log.d("DEBUG", "Widget click by user");
		 	if (GlobalRadio.getPlayerState()=="STOP") {
		 		GlobalRadio.setPlayerState("PLAY");
		 		ctrlPlayer(context,"PLAY");
		 	}
		 	else if (GlobalRadio.getPlayerState()=="PLAY") {
		 		GlobalRadio.setPlayerState("STOP");
		 		ctrlPlayer(context,"STOP");
		 	}	
		 	else {
		 		Log.d("DEBUG","CLICK but can't make any action");
		 	}
	 	}
	 	else if (intent.getAction() == "CLICK" && GlobalRadio.getClickState() != "READY") {
		 	Log.d("DEBUG", "First click of Widget by Android, set the CLICK available ");
		 	GlobalRadio.setClickState("READY");		 	
	 	}
	 	else if (intent.getAction() == "android.appwidget.action.APPWIDGET_UPDATE") {
	 		// DO nothing
	 		GlobalRadio.setClickState("READY");
	 	}
	 	else if (intent.getAction() == "android.appwidget.action.APPWIDGET_DELETED" || intent.getAction() == "android.appwidget.action.APPWIDGET_DISABLED") {
	 		// Is removed from home screen
	 	}
	 	else {
	 		Log.d("DEBUG", "Other action not monitored : " + intent.getAction().toString());
	 	}
	}
	public void ctrlPlayer(Context context,String s){
		if (s == "PLAY"){
			mediaPlayer = MediaPlayer.create(context, Uri.parse("http://69.163.34.200:8000/1/listen.mp3"));		            
	 		mediaPlayer.start();	
		}
		else {
	 		mediaPlayer.stop();	
		}	
	}

Et voici le Log;

Link to comment
Share on other sites

Bonjour,

 

Le problème que tu rencontres, c'est que tu fais des opérations longues (accès réseau) dans le thread principal (thread par défaut). Et Android n'autorise pas cela, et veille au grain, d'où le time-out.

Il faut que tu déportes les opérations longues dans un thread, typiquement géré dans un Service

 

PS: en Java, pour un test d'égalité des chaines de caractères, il ne faut pas utiliser l'opérateur == , mais la méthode equals ( if (s.equals("PLAY)) au lieu de if (s == "PLAY") )

Link to comment
Share on other sites

J'ai beau créer un service, mais mon click ne marche pas avec le service, je ne peux pas non plus connaitre l'était du MediaPlayer, meme avec une commande pour aller chercher l'infos dans le service, Il a trop de class et je m'y perd, sérieux j'ai besoin d'un bon coup de main pour comprendre le principe de tout. La j'ai tellement modifié mon code que plus rien marche.

 

Pour créer le service je me suis inspiré de http://www.vogella.com/tutorials/AndroidWidgets/article.html

J'ai transféré le MediPlayer dans ce service, j'ai également déplacer le RemoteViews, AppManager etc.. dans ce service. Mais un élément à la fois.

 

Vraiment Java c'est de la m*rde, j'y comprend rien, pourtant avec du HTML/PHP, Delphi j'arrive a pondre de quoi.....

 

Aidez moi!!! Je veux simplement un Widget que quand on click dessus mon stream démarre (et change l'icone) et quand ont reclick il le stop (et rechange l'image), me semble c'est simple ?

Link to comment
Share on other sites

Bon, j'ai pratiquement réussi à tous faire marcher, mais je me trouve avec un ANR lorsque je tente de me connecter à la radio.

 

- Le widget s'ouvre, le service démarre.

- L'icone change en offline (normal)

- Je click, il change une valeur de NOTREADY a READY (normal pour le moment)

- Je reclick, il demande un démarrage de la lecture

- PAF, Après 5 secondes, un ANR avec un trace; 

 

Voici mon code actuel;

 

- Pour le Widget (Provider) : 

- Pour les valeurs global : 

- Pour le service du Widget : 

 

Alors en simple, il me reste qu'a démarrer un stream sans planter le Widget. D'autres améliorations seront requise mais il n'inquiète pas pour le moment (comme fermer le/les timer quand le widget est fermé).

 

Merci de votre aide, et en passant, mon code est libre alors si il peu servir pour l'un de vos projet, vous pouvez le copier.

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...