2014-09-21 2 views
0

BroadcastReceiver를 사용하여 전화를 부팅 할 때 일부 작업을 수행하는 Android 앱을 개발 중입니다. Android 4.4.4 KitKat을 실행하는 Nexus 5에서는 정상적으로 작동하지만 친구가 Android 2.3.6을 실행하는 휴대 전화에서이 기능을 테스트 한 결과 제대로 작동하지 않았습니다. 다음과 같이 내 코드는 다음과 같습니다BroadcastReceiver가 Android 2.x에서 작동하지 않습니다.

public class PowerConnectionReceiver extends BroadcastReceiver { 

private static final int NOTIFICATION_ID = 1; 

@Override 
public void onReceive(Context context, Intent intent) { 

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setContentTitle("My app") 
      .setContentText("My notification...") 
      .setTicker("My awesome notification"); 

    NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notifManager.notify(NOTIFICATION_ID, notifBuilder.build()); 
} 

}는 브로드 캐스트 리시버에서

, 단순히 알림을 보여줍니다. 그 후, 나는의 AndroidManifest.xml에 브로드 캐스트 리시버를 등록 :

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

    ...More code... 

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

    ...More code... 

    <receiver 
     android:name=".activities.PowerConnectionReceiver" 
     android:enabled="true" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

    ... More code... 
    </application> 

나는 안드로이드 2.x에서 내 응용 프로그램 작업을 위해 무엇을 할 수 있는가?

미리 감사드립니다. 마지막으로

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

을 경우와 같은 수신기 코드를 수정하려고 : internalOnly에 설치 위치를 설정뿐만 아니라

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

<application 
.... 

을 :

답변

0

뿐만 아니라 수신기의 외부 권한을 설정하십시오 위의 경우 여전히 작동하지 않습니다.

<receiver android:name=".activities.PowerConnectionReceiver" 
     android:enabled="true" 
     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> 
+0

감사합니다. 나는 그것을 시험해 볼 것이고, 나는 그것이 나의 문제를 해결 하는지를 볼 것이다. – fergaral

관련 문제