Aller au contenu

Popup sur lockscreen


flunk

Recommended Posts

Bonjour,

Je suis à la recherche du code java me permettant d'affiché une popup sur le lockscreen.

J'ai trouvé quelques trucs mais rien ne fonctionne...

Je ne suis pas très bon en Java, je développe mes application sur Windev, ça me permet d’évité d’apprendre un nouveau langage.

Voici le code le plus avancé que j'ai pu adaptée :

import android.app.*;
import android.view.*;
import android.content.*;
import android.os.*;

public static void JavaVerrouillageEcran() {
KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("IN");
kl.disableKeyguard();

PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
PowerManager.WakeLock wl=pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "My_App");
wl.acquire();

Builder adb = new AlertDialog.Builder(this);
adb.setMessage("Testing");
adb.setCancelable(false);
adb.setNeutralButton("Close",new DialogInterface.onclickListener(){
@Override
public void onclick(DialogInterface dialog, int which) {
kl.reenableKeyguard();
}
});
AlertDialog ad = adb.create();
ad.show();

wl.release();
}

Il me retourne 5 erreurs des plus étonnante :


Ligne de commande : "C:\Program Files\Java\jdk1.7.0_21\bin\javac.exe" -encoding UTF-16LE -nowarn -source 1.5 -target 1.5 -d bin\classes -bootclasspath "C:\Users\Lucas\AppData\Local\Android\android-sdk\platforms\android-17\android.jar" gen\com\appli\*.java src\com\appli\wdgen\*.java -classpath "libs"

Erreur retournée :
src\com\appli\wdgen\GWDCPCOL_ProceduresJava.java:32: error: cannot find symbol
KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);
												 ^
symbol: variable KEYGUARD_SERVICE
location: class GWDCPCOL_ProceduresJava
src\com\appli\wdgen\GWDCPCOL_ProceduresJava.java:36: error: cannot find symbol
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
											 ^
symbol: variable POWER_SERVICE
location: class GWDCPCOL_ProceduresJava
src\com\appliwdgen\GWDCPCOL_ProceduresJava.java:40: error: cannot find symbol
Builder adb = new AlertDialog.Builder(this);
^
symbol: class Builder
location: class GWDCPCOL_ProceduresJava
src\com\appli\wdgen\GWDCPCOL_ProceduresJava.java:40: error: non-static variable this cannot be referenced from a static context
Builder adb = new AlertDialog.Builder(this);
								 ^
src\com\appli\wdgen\GWDCPCOL_ProceduresJava.java:40: error: no suitable constructor found for Builder(GWDCPCOL_ProceduresJava)
Builder adb = new AlertDialog.Builder(this);
		 ^
constructor Builder.Builder(Context,int) is not applicable
 (actual and formal argument lists differ in length)
constructor Builder.Builder(Context) is not applicable
 (actual argument GWDCPCOL_ProceduresJava cannot be converted to Context by method invocation conversion)
Note: src\com\appli\wdgen\GWDCPCOL_ProceduresJava.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors

J'ai besoin d'aide, c'est pourquoi je fais appelle une fois de plus à la communauté.

D'avance Merci :)

Lien vers le commentaire
Partager sur d’autres sites

  • 2 months later...

Hello,

Ca date mais j'y répond quand meme.

Toutes ces erreurs viennent du fait que tu n'as aucun contexte car ta classe n'hérite pas d'Activity et ne recoit pas de contexte en parametre...

Il faut donc que tu passe un parametre Context context, et ensuite au lieu d'écrire :

KeyguardManager km = (KeyguardManager)getSystemService(KEYGUARD_SERVICE);

Tu écris

KeyguardManager km = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE);

 

C'est la meme chose pour l'erreur suivante.

 

Quant aux 3 autres erreurs, tu utilises un "this" qui n'a pas de sens... a la place il faut aussi donner "context"

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...