有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 安卓4。4在出厂重置设备后,系统应用程序无法接收启动完成的广播

下面是我的舱单。xml

<uses-sdk
    安卓:minSdkVersion="19"
    安卓:targetSdkVersion="19" />
<uses-permission 安卓:name="安卓.permission.RECEIVE_BOOT_COMPLETED" /> 
<uses-permission 安卓:name="安卓.permission.SYSTEM_ALERT_WINDOW"/>

<application
    安卓:allowBackup="true"
    安卓:icon="@drawable/ic_launcher"
    安卓:label="@string/app_name"
    安卓:theme="@style/AppTheme" >

    <!-- 
    <activity
        安卓:name=".MainActivity"
        安卓:label="@string/app_name" >
        <intent-filter>
            <action 安卓:name="安卓.intent.action.MAIN" />

            <category 安卓:name="安卓.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
     -->

    <receiver 安卓:name="com.tcl.receiver.BootReceiver">  
       <intent-filter>  
           <action 安卓:name="安卓.intent.action.BOOT_COMPLETED" />  
       </intent-filter>  
   </receiver>

   <service 安卓:name="com.tcl.factoryresetservice.SystemMessageService" 安卓:exported="false">
        <intent-filter>
            <action 安卓:name="com.tcl.factoryresetservice.SystemMessageService" />
            <category 安卓:name="安卓.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);

    }
}

在工厂重置设备后,系统运行,但我的服务不运行。如果我重新启动,它将成功运行。为什么会这样,请帮助我们,谢谢


共 (1) 个答案

  1. # 1 楼答案

    您的用户权限是正确的

    <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>