如何在android中显示简单的通知? [英] How can I display a simple notification in android?

查看:108
本文介绍了如何在android中显示简单的通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Android的通知栏中显示简单通知?请帮我解决最简单的解决方案。

How can I display a simple notification in notification bar in Android? Please help me with the easiest solution.

推荐答案

我假设您在通知栏中询问通知。如果是这样,请尝试此代码,

I assume you are asking about notification in notificationbar.If its so,Try this code,

private void showNotification(String eventtext, Context ctx) {



    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.noti_icon,
            text, System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this
    // notification
    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
            new Intent(ctx, MainActivity.class), 0);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(ctx, "Title", eventtext,
            contentIntent);

    // Send the notification.
    mNotificationManager.notify("Title", 0, notification);
}

这篇关于如何在android中显示简单的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆