接收消息时如何工作通知

时间:2013-11-28 07:07:06

标签: java android notifications sms

我正在申请接收消息,但我希望在收到消息时显示通知

请问,它是如何工作的

1 个答案:

答案 0 :(得分:1)

PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Player.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
notification = new Notification();
notification.tickerText = "App Name";
notification.icon = R.drawable.icon;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
try {
        notification.setLatestEventInfo(getApplicationContext(), "App Name", "AppName~ ", pi);
} catch (Exception e) {

        e.printStackTrace();
}
startForeground(01, notification);