在我的清單文件中,我已聲明接收者。 (如下)當應用程序未運行時BroadcastReceiver不工作
<receiver android:name=".OnAlarmReceive" />
但是,一旦我關閉我的應用程序,我無法獲得警報和通知。顯然,我的Broadcast receiver
中的OnReceive
電話永遠不會發出。
public class OnAlarmReceive extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent arg1)
{
//various stuff
}
}
在MainActivity內部,我的報警管理器類如下所示。
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent("MY_ALARM_NOTIFICATION");
intent.setClass(this, OnAlarmReceive.class);
intent.putExtra("message", message);
PendingIntent pendingIntent = PendingIntent
.getBroadcast(MainActivity.this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Calendar timeCal = Calendar.getInstance();
timeCal.set(Calendar.HOUR_OF_DAY, hour);
timeCal.set(Calendar.MINUTE, minutes);
alarmManager.set(AlarmManager.RTC_WAKEUP, timeCal.getTimeInMillis(), pendingIntent);
,我的表現爲是如下:
<receiver android:name=".OnAlarmReceive">
<intent-filter android:priority="1">
<action android:name="MY_ALARM_NOTIFICATION"/>
</intent-filter>
</receiver>
我應該怎麼才能收到通知/報警,即使我已經關閉我的應用程序做。後臺服務?
報警接收是否一樣?因爲你給了短信 – tony9099 2013-05-06 08:58:38