0
我正在開發一個Android應用程序,該應用程序在電話啓動時使用BroadcastReceiver來完成一些工作。在運行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>
我能做些什麼,使在Android 2.x的我的應用程序的工作?
在此先感謝。
謝謝!我會試試看,我會看看它是否能解決我的問題。 – fergaral 2014-09-23 22:34:31