Comment utiliser le Temps Réel Écoulé dans Android?

Je veux développer une application. L'application dispose d'un spinner liste déroulante. La liste déroulante a 3 option (30min, 1h, 2h). Lorsque, par exemple, 30min est pressé, je veux commencer un Temps Réel écoulé pour 30min et je veux désactiver le wifi, cela signifie que, après 30min le wifi doit être éteint.

Le logcat me montre un NullPointer Exception.

Voici mon code

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.SystemClock;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;
public class SpinnerTimeOnItemSelectedListener extends Activity implements AdapterView.OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long 
if(parent.getItemAtPosition(position).toString().equals("Zeit auswählen") || parent.getItemAtPosition(position).toString().equals("Select Time")){
onNothingSelected(parent);
} else if (parent.getItemAtPosition(position).toString().equals("30min")){
Intent intent = new Intent(SpinnerTimeOnItemSelectedListener.this, ConnectionManager.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(SpinnerTimeOnItemSelectedListener.this, 0, intent, 0);
long firstTime = SystemClock.elapsedRealtime();
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, firstTime, 5000, pendingIntent);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
//Wenn es einen ElapsedRealTimeAlarm gibt, soll er gecancelt werden
//Ansonsten nichts
;
}
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

Et dans cette catégorie, le wifi devrait être géré (allumé/éteint)

public class ConnectionManager extends BroadcastReceiver {
/**
*
* @param context The Context in which the receiver is running.
* @param intent  The Intent being received.
*/
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "I'm running", Toast.LENGTH_SHORT).show();
}
}

Erreur de le logcat:

07-24 17:35:17.503    5430-5430/com.falkenherz.abusufean.batterycooler E/AndroidRuntime FATAL EXCEPTION: main
Process: com.falkenherz.abusufean.batterycooler, PID: 5430
java.lang.NullPointerException
at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:104)
at android.app.PendingIntent.getService(PendingIntent.java:522)
at com.example.ali.turnoffwifi.SpinnerTimeOnItemSelectedListener.onItemSelected(SpinnerTimeOnItemSelectedListener.java:42)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:956)
at android.widget.AdapterView.access$200(AdapterView.java:49)
at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:920)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

L'erreur sur cette ligne:

PendingIntent pendingIntent = PendingIntent.getBroadcast(SpinnerTimeOnItemSelectedListener.this, 0, intent, 0);

Comment puis-je résoudre ce problème?
Grâce

InformationsquelleAutor Ali | 2014-07-24