通知

作者: dev晴天 | 来源:发表于2018-08-11 19:41 被阅读0次
发送通知demo:


public class NotificationActivity extends AppCompatActivity {

    private NotificationManager nm;// 通知的服务

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification);
    }
    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    public void send_notification(View view){
       /* 点击图标 跳转 使用 这两句代码   夹下面的 .setContentIntent(pi)
       *  PendingIntent通过静态方法获得实例可以根据需求选择getActivity()
       *  getBroadcast() 或 getService()
       * */
        Intent intent = new Intent(this,MainActivity.class);
        PendingIntent pi =  PendingIntent.getActivity(this,0,intent,0);
        //1 获得管理者
        nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        // 2获得通知构造者   连时调用
        Notification notification =  new  Notification.Builder(this)
                .setContentTitle("我是通知栏标题")
                .setContentText("我是通知栏内容")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                .setAutoCancel(true)
                .setContentIntent(pi)
                .build();
        // 3 发送通知  参数 int (标明不同的通知) , Notification notification
        nm.notify(1,notification);
    }
    /* 补充  setsounds(Uri.fromFile(""))
    *        setVibrate(new long[]{}) // 加权限
    *        setLight(color.red int int )
    *        
    * */
}

相关文章

  • 通知!通知!

    我到现在已有三位粉丝,现在我要开始发福利啦! 我下一篇文章开始写小说啦!希望大家多多支持!谢谢!

  • 通知!通知!

    小仙近日找了一个编辑(啥也不是),有事请找她昂, @小编辑染染 她负责我的更新日常,而且此人闲的要死,如有评论,都...

  • 通知--通知

    因为事情开始多起来了,很难保证下午开始更了,所以决定了,之后每天早上更。 假期结束,很多事情需要去处理,现在不...

  • 通知-通知

    昨天下午,写了一篇文章,可有敏感词,没有成功通过审核,今天晚上,努力搞一篇出来,换另外一个故事,昨天的那个故事,我...

  • 通知! 通知 ! 通知书 !

  • 重要通知!重要通知!重要通知!

    非常感谢小伙伴的关注和支持,以后摄影相关内容将不再这里更新。 喜欢毒家摄影指南内容的小伙伴欢迎关注微信公众号:sm...

  • 推送通知-后台通知/静默通知

    后台远程推送iOS7开始允许应用收到通知后直接在后台(background)状态下运行一段代码,而无需用户点击,可...

  • 通知:本地通知和远程通知

    通知中心(NotificationCenter)和通知(UILocalNotification)是雷锋和雷峰塔的关...

  • Spring 返回通知 异常通知 环绕通知

    返回通知 在方法正常返回结果后的通知。返回通知可以访问到方法的返回值。 示例(附带返回结果的返回通知): 异常通知...

  • 通知与移除通知

    [[NSNotificationCenterdefaultCenter]postNotificationName:...

网友评论

      本文标题:通知

      本文链接:https://www.haomeiwen.com/subject/mczdbftx.html