public class NotificationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
}
public void notifyNew(View view){
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Builder(this);
builder.setContentTitle("通知标题");
builder.setContentText("帖子内容");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
Notification notification = builder.build();
nm.notify(0, notification);
}
@SuppressWarnings("deprecation")
public void notifyOld(View view){
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "通知来了", System.currentTimeMillis());
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:123456"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(this, "标题", "内容", contentIntent);
nm.notify(0, notification);
}
}
Android 通知Notification的两种实现方法
最新推荐文章于 2024-09-22 20:30:22 发布