我正在執行一個應用程序,在該設備啓動完成時我要調用一個數字。我的代碼是這樣的:設備啓動完成時啓動服務
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
System.out.println("**inside onRecevier");
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.test.app.TestService");
context.startService(serviceIntent);
}
首先我創建了BroadcastReceiver。我註冊了這個接收器清單文件是這樣的:
<receiver android:name="TestReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
在接收機中我叫下面的服務:
public class TestService extends Service{
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
System.out.println("**inside onCreate");
super.onCreate();
Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
Intent call = new Intent(Intent.ACTION_CALL,Uri.parse("tel:+5555"));
startActivity(call);
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
System.out.println("**inside onDestroy");
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
System.out.println("**inside onStart");
super.onStart(intent, startId);
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
}
}
,當我試圖啓動應用越來越強制關閉後啓動的設備。如何在android中做到這一點? Thanx提前
請張貼異常的描述和堆棧跟蹤。 – Ash 2012-01-17 15:30:40