0
我想在完成電話啓動時啓動一項新服務。所以我創建廣播接收器爲如下廣播中的服務爲空接收器
@Override
public void onReceive(final Context context, final Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent mServiceIntent = new Intent("com.android.reminder.BootService");
//mServiceIntent.setAction("com.android.reminder.BootService");
ComponentName service = context.startService(mServiceIntent);
if (service==null) {
// something really wrong here
Toast.makeText(context, "Sorry, Service is found null",
Toast.LENGTH_LONG).show();
}else{
Toast.makeText(context, "Service is not null",
Toast.LENGTH_LONG).show();
}
}
}
和申報清單文件 -
.....
<service
android:enabled="true"
android:name="com.android.reminder.BootService">
</service>
<receiver
android:name="AlarmReceiver"
android:process=":remote" >
</receiver>
<receiver
android:enabled="true"
android:name=".BootReceiver" >
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
</application>
我發現麪包是「對不起,服務發現空」和服務未啓動.. ...
請幫助我.... THX提前..
非常感謝你的工作.... – 2013-03-05 06:04:19
很高興,它的工作原理。請接受這個答案。 – Sunny 2013-03-05 06:10:05