V4的NotificationManagerCompat,v7的NotificationCompat
来源:互联网 发布:德国 帅哥 推倒 知乎 编辑:程序博客网 时间:2024/06/14 09:44
V4的NotificationManagerCompat,v7的NotificationCompat
其实没啥,NotificationManagerCompat相比与NotificationManager,兼容性更好,还是用新的比较好
v7包的NotificationCompat,同理,对比v4的NotificationCompat,和普通的Notification,兼容性更好,当然用最新,
package com.example.notificationtest;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.graphics.BitmapFactory;import android.graphics.Color;import android.net.Uri;import android.os.Bundle;import android.support.v4.app.NotificationManagerCompat;import android.support.v7.app.AppCompatActivity;import android.support.v7.app.NotificationCompat;import android.util.Log;import android.view.View;import android.widget.Button;import java.io.File;public class MainActivity extends AppCompatActivity implements View.OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button sendNotice = (Button) findViewById(R.id.send_notice); sendNotice.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.send_notice: Intent intent = new Intent(this, NotificationActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0); NotificationManager managera=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); NotificationManagerCompat manager = NotificationManagerCompat.from(this); Log.i("onClick: ", "onClick: "+manager.areNotificationsEnabled()); Notification notification = new NotificationCompat.Builder(this) .setContentTitle("This is content title") .setContentText("This is content text") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setContentIntent(pi) .setSound(Uri.fromFile(new File("/system/media/audio/ringtones/Luna.ogg"))) .setVibrate(new long[]{0, 1000, 1000, 1000}) .setLights(Color.GREEN, 1000, 1000) .setDefaults(NotificationCompat.DEFAULT_ALL) .setStyle(new NotificationCompat.BigTextStyle().bigText("Learn how to build notifications, send and sync data, and use voice actions. Get the official Android IDE and developer tools to build apps for Android.")) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.big_image))) .setPriority(NotificationCompat.PRIORITY_MAX) .build(); manager.notify(1, notification); break; default: break; } }}
阅读全文
0 0
- V4的NotificationManagerCompat,v7的NotificationCompat
- Android v4包使用NotificationCompat.Builder 遇到undefined的问题
- android-support-v4 v7 v13的区别
- Android Support ;v4、v7、v13的区别
- Android Support ;v4、v7、v13的区别
- Android Support ;v4、v7、v13的区别
- Android Support v4、v7、v13的区别
- Android Support V4, V7, V13的作用
- Android Support ;v4、v7、v13的区别
- Android Support v4、v7、v13的区别
- 关于V4、V7包重复的问题
- Android v4、v7、v13 的区别
- V4与v7的冲突,记录下来
- Android Support V4,V7,V13的区别
- Android Support v4,v7,v13的区别以及 v4,v7包冲突问题
- Andriod Support V4 V7 V13的应用场景
- Android Support v4,v7,v13之间的区别
- Android Support v4、v7、v13的区别和应用场景
- 遥感影像镶嵌软件功能介绍
- PyQt5中文基础教程12 俄罗斯方块游戏
- TCP/IP学习笔记(一)基础知识
- 原型模式
- hdu 2586 How far away? 【LCA】 解题报告
- V4的NotificationManagerCompat,v7的NotificationCompat
- 简单的冒泡排序
- php简单的抽奖概率算法
- 一起学Java_Java语言基础(2)
- RunLoop
- 图形绘制Canvas类的方法save()和restore()的区别
- react同级组件之间传值
- Thinkphp自定义分页(二)
- 学会使用Linux命令行做简单的数据分析