如何在特定时间在状态栏中获取通知,我尝试了这一点,但每个特定时间都会调用pendingIntents活动。我希望调用状态栏的通知。请帮忙
public class MainActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
Notification("abduct: ","kidnap");
}
@SuppressWarnings("deprecation")
private void Notification(String notificationTitle, String notificationMessage)
{
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(R.drawable.icon, "First word", 50000);
notification.setLatestEventInfo(MainActivity.this, notificationTitle, notificationMessage, null);
notificationManager.notify(1, notification);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), 1*60*60 , pendingIntent ); //set repeating every 24 hours
}
}
答案 0 :(得分:0)
问题在于您提供PendingIntent
的{{1}}。通过AlarmManager
创建它,实际上是指示它在指定时间过后开始您的活动。
您需要做的是:
PendingIntent.getActivity()
并在AndroidManifest.xml文件中对其进行配置。BroadcastReceiver
提供AlarmManager
向该接收者发送广播(PendingIntent
)。PendingIntent.getBroadcast()
中,构建并显示通知。您可以找到简明扼要的教程here。