android notification处理

public class NotificationDeal
{
   
    private Context myContext;
   
    public NotificationDeal(Context context)
    {
        this.myContext = context;
    }
   
    public void insertNotification(String tickerText,String contentTitle,String contentText)
    {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) myContext.getSystemService(ns);
        int icon = R.drawable.logo;
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        //CharSequence tickerText = "titile";
        //定义下拉通知栏时要展现的内容信息
        //CharSequence contentTitle = "intro_index";
        //CharSequence contentText = "intro";

        Intent notificationIntent = new Intent(myContext, VoiceIdentify.class);

        PendingIntent contentIntent = PendingIntent.getActivity(myContext, 0,notificationIntent, 0);

        notification.setLatestEventInfo(myContext, contentTitle, contentText,contentIntent);

        //用mNotificationManager的notify方法通知用户生成标题栏消息通知

        mNotificationManager.notify(1, notification);
    }
   
}
发布了45 篇原创文章 · 获赞 1 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章