闲坐敲棋

有约不来过夜半,闲敲棋子落灯花

导航

由于做Android 播放器,要实现程序隐藏,展现,通过 Notification  实现切换。

Notification  代码如下:

 String notificationMessage = ((Audio) obj).name_label;
 Notification notification = new Notification(R.drawable.icon,notificationMessage, System.currentTimeMillis());
  try {
        Intent contentIntent = new Intent(getApplicationContext(),
        Class.forName("com.***.***.****")); // 加载类,如果直接通过类名,会在点击时重新加载页面,无法恢复最后页面状态。
        contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
       PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, contentIntent,0);
       notification.setLatestEventInfo(PlayerService.this,getString(R.string.app_name), notificationMessage,pendingIntent);
       notification.flags |= Notification.FLAG_ONGOING_EVENT;
       mNotificationManager.notify(id,notification);

    } catch (ClassNotFoundException ex) {

          // 日志
   }