码迷,mamicode.com
首页 > 其他好文 > 详细

BroadcastReceiver

时间:2016-10-18 23:32:04      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:broadcast

package com.android.broadcastreceiver;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class HelloBroadcastReceiver  extends BroadcastReceiver{
  private Context context;
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        this.context=context;
        showNotification(intent);
    }
    private void showNotification(Intent intent) {
    
        // TODO Auto-generated method stub
        
        NotificationManager notificationManager=(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        
        
        Notification notification=new Notification(R.drawable.ic_launcher,intent.getExtras().getString("context"),System.currentTimeMillis());
        
        PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, new Intent(context,MainActivity.class), 0);
        
        notification.setLatestEventInfo(context, intent.getExtras().getString("context"), null, pendingIntent);
        
        
        notificationManager.notify(R.layout.activity_main,notification);
    }

}


BroadcastReceiver

标签:broadcast

原文地址:http://11657004.blog.51cto.com/11647004/1863074

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!