【问题标题】:Show default notification bar in Android在 Android 中显示默认通知栏
【发布时间】:2015-04-22 05:21:46
【问题描述】:

我在互联网上搜索了很多,但找不到答案。

我正在开发一个启动器项目,并且在单击按钮时,我想启动默认的通知栏。是否有任何API

【问题讨论】:

  • 您是否尝试过任何教程?
  • 你想让通知栏在点击按钮时向下滑动?

标签: java android eclipse adt


【解决方案1】:

您可以使用以下代码实现 android 默认通知。你可以自定义。

// Invoking the default notification service
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this);

    mBuilder.setContentTitle("ur titlw");
    mBuilder.setContentText("ur content");
    mBuilder.setTicker("ur sticker");
    mBuilder.setSmallIcon(R.drawable.uricon);

    // Increase notification number every time a new notification arrives
    mBuilder.setNumber(++numMessagesOne);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, ur activity where this notification shout appear);
    resultIntent.putExtra("notificationId", "test");

    // This ensures that navigating backward from the Activity leads out of
    // the app to Home page
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent
    stackBuilder.addParentStack(ur activity where it returns when click on the notification);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_ONE_SHOT // can only be used once
            );
    // start the activity when the user clicks the notification text
    mBuilder.setContentIntent(resultPendingIntent);

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

    // pass the Notification object to the system
    myNotificationManager.notify(notificationIdOne, mBuilder.build());

我希望这会有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    相关资源
    最近更新 更多