1

여러 가지 다른 예를 시도해 보았습니다. 서비스를 통해 알림을받은 후 BroadcastReceiver에서 로그를 수신하도록 마침내 관리했습니다. 여전히 문제는 지속됩니다.BroadcastReceiver는 adb 셸을 처음 실행 한 후에 만 ​​작동합니다.

apk를 설치하거나 빌드 한 후 usb에서 실행하면 BroadcastReceiver가 의도를 수신하지 않습니다. 수동으로 애플리케이션을 12 번 실행 한 다음 다시 시작 (전원 켜기/끄기)하고 아무 것도하지 않으려 고 노력했습니다. 짜잔,

ADB 쉘 오전 방송 -a android.intent.action.BOOT_COMPLETED -n com.myapp.example/.BootCompletedReceiver

그리고 : 그 후, 나는 ADB 쉘을 디버깅하려고 ! 그것은 효과가 있었다. 재부팅으로 확인했습니다. 그 후, 나는 응용 프로그램을 다시 시작하고 다시 - 작동하지 않았다. 내가 adb 쉘로 시도한 후에 - 다시, 모든 것이 작동하고있다. 처음부터 adb 쉘 명령을 실행 한 후에 만 ​​솔기가 작동해야합니다.

HTC ONE과 함께 AVD (내 컴퓨터에서 너무 느림)로 시도하지 않았습니다. (HTC ONE 문제도 확인했는데, HTC 전화의 일부 버전에서는 문제가 있음을 알고있었습니다. 도움).

내 매니페스트입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.myapp.example" > 

<uses-permission android:name="android.permission.BLUETOOTH" /> 
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppThemeWhiteActionBar" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 

     android:screenOrientation="portrait" 
     android:theme="@style/AppThemeWhite" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    ... 
    <receiver android:name=".BootCompletedReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.QUICKBOOT_POWERON" /> 
     </intent-filter> 
    </receiver> 
    <receiver android:name=".util.AlarmReceiver"/> 
    <service android:name=".NotifyingDailyService" > 
    </service> 
</application> 

그리고 사람들은 BootCompletedReceiver 및 NotifyingDailyService (여기 많은 예에서와 거의 동일)입니다

public class BootCompletedReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent arg1) { 
    Log.w("boot_broadcast_poc", "starting service..."); 
    context.startService(new Intent(context, NotifyingDailyService.class)); 
} 

} 

public class NotifyingDailyService extends Service { 

@Override 
public IBinder onBind(Intent arg0) { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
public int onStartCommand(Intent pIntent, int flags, int startId) { 
    NotificationManager mNotificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification.Builder builder = new Notification.Builder(this); 
    builder.setSmallIcon(R.drawable.ic_launcher); 
    builder.setContentTitle(getString(R.string.random_string)); 
    builder.setContentText(getString(R.string.random_string)); 
    builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS); 
    mNotificationManager.notify(12345, builder.build()); 
    return super.onStartCommand(pIntent, flags, startId); 
} 
} 

답변

0

설치 앱 충분하지 않습니다 을 (를) 듣고 BOOT_COMPLETED 브로드 캐스트를 청취하십시오. BroadcastReceiverBOOT_COMPLETED 시스템 브로드 캐스트를들을 수있게하려면 응용 프로그램을 한 번 시작해야합니다. 즉, 맞춤 앱 클래스 또는 항목을 한 번 시작해야합니다. 이 동작은 보안상의 이유로 의도적으로 설계된 동작입니다.

blog에 대한 자세한 내용은 CommonsWare에서 읽을 수 있습니다.

+0

그래, 안드로이드 3.1 이후로 그 문제를 안다. 문제는 응용 프로그램을 시작하고 처음 부팅 할 때마다 거의 모든 활동을 실행한다는 것입니다. 어쨌든 adb 쉘은 BOOT_COMPLETED를 듣기 시작하도록 "강제"합니다. –

+0

나는 본다. 매니페스트의 수신기에 를 추가해보세요. –

0

Android에서 시작 프로그램을 제한하는 옵션이 있습니다. 나는 당신의 응용 프로그램도 제한되어 있다고 생각합니다. 설정 -> 개인 -> 시작 관리자로 이동하십시오. 여기서 boot_completed 브로드 캐스트 수신을 허용하거나 제한 할 수 있습니다.

+0

시작 관리자가 거의없는 안드로이드 장치가 있습니다. – soger

관련 문제