2015-10-13 137 views
0

我安装并打开它,并重新启动我的电话,但我接收我以前不接收广播开始我的服务,并没有记录。我的广播接收机不能得到BOOT_COMPLETED广播

我的手机是华硕LF2。

我如何开始我的设备引导服务完成?

我的接收机

public class BootReceiver extends BroadcastReceiver { 

    private final String TAG = getClass().getSimpleName(); 
    public BootReceiver() { 
    } 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.d(TAG , "Deyu onReceive " + intent.getAction()); 
     context.startService(new Intent(context, AlarmMessageService.class)); 
    } 
} 

我的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="go.deyu.dailytodo" 
    android:installLocation="internalOnly"> 

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

    <application 
     android:name=".app.App" 
     android:allowBackup="true" 
     android:icon="@mipmap/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=".receiver.BootReceiver" 
      android:permission="android.permission.RECEIVE_BOOT_COMPLETED" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
       <action android:name="android.intent.action.QUICKBOOT_POWERON" /> 
      </intent-filter> 
     </receiver> 

     <service 
      android:name=".AlarmMessageService" 
      android:enabled="true"> 
     </service> 
    </application> 

</manifest> 
+0

这段代码在三星的手机是工作.... –

回答

2

我觉得为什么我的在我的手机应用程序不能得到启动完成广播。

有一个在我的华硕手机自动启动管理器设置。

当我让我的应用程序自动启动,我的应用程序工作的优良....

Ausu LF2 Auto-start Manager

+0

你只是保存我的一天! – zoom

+0

如何以编程方式执行此操作?从Play商店安装后,我们无法强制用户执行此操作。 –

1

<receiver>元件删除android:permission="android.permission.RECEIVE_BOOT_COMPLETED"

+0

我只是尝试,但还没有收到广播。 –

+0

@Deyu瑜:你安装/升级应用程序后运行的活动? – CommonsWare

+0

是的,我安装后运行。 –

1

下面的代码尝试

<receiver 
     android:name=".receivers.RestartReceiver" 
     android:enabled="true" 
     android:exported="true" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
</receiver> 
0

的Android 3.1或以上,如果你想对付android.intent.action.BOOT_COMPLETED broadcastreceiver.You一定要注意这一点:

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

1.确保你有你安装后打开你的应用程序。我想你做到了。

2.检查您的Android手机设备设置:设置 - >应用程序 - >您的应用程序 - >力Stop.If强制停止开启,请关闭它。

3.Another点你应该检查是android:name=".receiver.BootReceiver",要小心的路径,也许系统无法找到你的BootReceiver。