現在,當我運行這個什麼都不會發生
公共類MYSERVICE延伸服務{
@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 ;
}
}
u能請與代碼幫助? – shantanu
在ApiDemos/src/com/example/android/apis/app/LocalService.java和ApiDemos/src/com/example/android/apis/app/AlarmService.java中提供了一些很好的服務示例代碼,以及服務和一些代碼片段在http://developer.android.com/guide/components/services.html。我建議從那裏開始,然後在寫入 – levis501
謝謝..之後再寫下其他問題。levis501 – shantanu