只设置了一个通知我希望个人通知显示我的代码是

时间:2017-03-25 05:17:13

标签: android android-layout android-notifications

我想个人通知显示和用户点击通知移动通知信息显示在结果活动画面   并且也没有在通知中设置大图标

我处理提醒申请,所以任何建议都告诉我

public void loopReminder() {
    for (int i = 0; i < 3; i++) {
        remindarNotification();
    }
}

public void remindarNotification() {
    Notification notification;
    AtomicInteger c = new AtomicInteger(0);
    int id = c.incrementAndGet();

    NotificationManager notificationManager = (NotificationManager)
            getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(this, Activity_Detail_Screen.class);

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);


    stackBuilder.addParentStack(Activity_Detail_Screen.class);



    stackBuilder.addNextIntent(notificationIntent);

    PendingIntent intent =
            PendingIntent.getActivity(this, 0, notificationIntent,       
            PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
            R.drawable.ic_reminder);

    String message = "Hello Notification with imagecccccccccccccccccccccccccccccc";

    String title = "Notification !!!";
    int icon = R.drawable.ic_notification;
    long when = System.currentTimeMillis();


    notification = new NotificationCompat.Builder(this)
            .setContentTitle(title)
            .setContentText(message)
            .setContentIntent(intent)
            .setSmallIcon(icon)
            .setLargeIcon(bitmap)
            .setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))

            .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
            .setLights(Color.RED, 3000, 3000)
            .setAutoCancel(true)
            .setDefaults(Notification.PRIORITY_HIGH)
            .setDefaults(Notification.DEFAULT_SOUND)
            .build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    Log.e("AutoIncriment", "Notification Id = > " + id);
    Toast.makeText(getApplicationContext(), "Id =" + id, Toast.LENGTH_SHORT).show();

    notificationManager.notify(id, notification);

}

1 个答案:

答案 0 :(得分:0)

public void fetchReminder() {

    String strCurrentDate = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
    String strCurrentTime = new SimpleDateFormat("HH:mm").format(new Date());
    Log.e("In fetchReminder", "Where Pass Date => " + strCurrentDate + " Time =>  " + strCurrentTime);

    String sel_user = "select * from Tb_Reminder where rem_date<='" + strCurrentDate + "' And rem_time<='" + strCurrentTime + "'";



    Cursor c_user = dbhelper.selectQuery(sel_user);
    Log.e("sel", "" + c_user.getCount());


    if (c_user != null && c_user.getCount() > 0) {

        if (c_user.moveToFirst()) {

            do {
                if (c_user.getCount() > 0) {


                    int rem_id = Integer.parseInt(c_user.getString(c_user.getColumnIndex("rem_id")));
                    String rem_gen_datetime = c_user.getString(c_user.getColumnIndex("rem_gen_datetime"));
                    String rem_desc = c_user.getString(c_user.getColumnIndex("rem_desc"));
                    String rem_date = c_user.getString(c_user.getColumnIndex("rem_date"));
                    String rem_time = c_user.getString(c_user.getColumnIndex("rem_time"));

                    Log.e("Fetch Value rem_id = ", +rem_id + "  rem_gen_datetime =" + rem_gen_datetime + "  rem_desc= " + rem_desc + "  rem_date= " + rem_date + "  rem_time= " + rem_time);
                    String ReminderDateTime = rem_date + "  " + rem_time;
                    addNotification(rem_id,rem_desc, ReminderDateTime);

                }

            } while (c_user.moveToNext());
        }
    } else {
        c_user.close();
        Log.e("Empty", "No Reminder is Available");
    }
    if (c_user != null) {
        c_user.close();
    }

}

//通知指导

private void addNotification(int rem_id,String desc,String reminderdatetime){

    Intent notificationIntent = new Intent(this, Activity_Detail_Screen.class);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    PendingIntent contentIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    int namMessage = 0;
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_notification)
                    .setContentTitle("Reminder")
                    .setContentText(desc + " On:" + reminderdatetime)
                    .addAction(R.drawable.ic_reminder, "Snooze", contentIntent)

                    .setContentIntent(contentIntent)
                    .setAutoCancel(true);



    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    manager.notify(rem_id, builder.build());
}
相关问题