下面是我的manifest.xml
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!--
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
-->
<receiver android:name="com.tcl.receiver.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name="com.tcl.factoryresetservice.SystemMessageService" android:exported="false">
<intent-filter>
<action android:name="com.tcl.factoryresetservice.SystemMessageService" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</service>
以下是我的接收代码:
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
//start the service at boot completed
if(intent.getAction().equals(BOOT_COMPLETED))
{
long curTime = System.currentTimeMillis();
Log.e(TAG,"Start SystemMessageService Service , curTime="+curTime);
Intent i = new Intent(context,SystemMessageService.class);
context.startService(i);
}
}
工厂重置设备后,系统运行,但我的服务没有运行。如果我重新启动,它会成功运行。为什么会这样,请帮助我们,谢谢。
答案 0 :(得分:0)
您的UserPermission是正确的
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
你的接收器应该是这样的 需要在接收器中添加权限
<receiver
android:name="com.tcl.receiver.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>