Maintenant, quand je cours ce rien ne se passe
MyService étend son service
public class {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
//@SuppressWarnings("null")
public int onStartCommand(Intent intent, int flags, int startId){
//Context context = null;
Toast.makeText(this, "service started", Toast.LENGTH_LONG).show();
startservice();
return Service.START_STICKY;
}
public void onDestroy(){
super.onDestroy();
Toast.makeText(this, "service stopped function", Toast.LENGTH_LONG).show();
}
private void startservice() {
// TODO Auto-generated method stub
//Toast.makeText(this, "service started function", Toast.LENGTH_LONG).show();
try
{
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
int rssi = connectionInfo.getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 10);
int percentage = (int) ((level/10.0)*100);
Toast.makeText(this, percentage, Toast.LENGTH_SHORT).show();
if(percentage<20){
Toast.makeText(this, "logout starting", Toast.LENGTH_LONG).show();
Intent uplIntent = new Intent(this,com.cyberoam.logout.class);
uplIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(uplIntent);
}
}
catch (Exception e)
{
return ;
}
return ;
}
}
Can u pls aider avec le code ?? – shantanu
Il y a un bon exemple de code pour les Services dans ApiDemos/src/com/exemple/android/apis/app/LocalService.java et ApiDemos/src/com/exemple/android/apis/app/AlarmService.java ainsi que des descriptions détaillées de Services et quelques extraits de code sur http://developer.android.com/guide/components/services.html. Je suggère de commencer là et ensuite écrire avec des questions supplémentaires que vous allez – levis501
merci .. levis501 – shantanu