Andriod Notification
来源:互联网 发布:华为ff软件下载 编辑:程序博客网 时间:2024/05/07 17:06
notification(通知)就是手机上面的弹出框。
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(MainActivity.this).build(); notificationManager.notify(1, notification);
想要什么效果的话就在.build()前面加上函数
public class MainActivity extends AppCompatActivity { public Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, lbj.class); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(MainActivity.this) .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher_round)) .setContentTitle("骑士总冠军!")//通知框的题目 .setAutoCancel(true)//点击后自动删除 //如果内容过长,会多行显示 //.setStyle(new NotificationCompat.BigTextStyle().bigText("首节上来,骑士状态低迷,公牛则率先发力,连续三次攻击内线得手。詹姆斯强攻篮下打成2+1,帮骑士开胡。之后,客队攻势有了起色,本节中段,JR-史密斯跳投打板得分,乐福三分也进,骑士实现反超。公牛并未慌张,瓦伦丁、波蒂斯三分连中,将比分咬住。可防守端,公牛却漏洞明显。詹姆斯助攻格林跳投入网,又亲自出手跳投得分,单节打完,骑士29-22暂时领先。")) // 内容长的话多出来的是省略号 .setContentText("首节上来,骑士状态低迷,勇士则率先发力,连续三次攻击内线得手。詹姆斯强攻篮下打成2+1,帮骑士开胡。之后,客队攻势有了起色,本节中段,JR-史密斯跳投打板得分,乐福三分也进,骑士实现反超。勇士并未慌张,杜兰特三分连中,将比分咬住。可防守端,勇士却漏洞明显。詹姆斯助攻格林跳投入网,又亲自出手跳投得分,单节打完,骑士29-22暂时领先。") // 实现页面跳转 .setContentIntent(pendingIntent) //播放音乐 //.setSound(Uri.fromFile(new File("/storage/emulated/0/kgmusic/download/1.mp3"))) //设置呼吸灯,没有出现预期效果 //.setLights(Color.GREEN, 1000, 20) .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.lbj))) //设置成默认模式的声音与振动 .setDefaults(Notification.DEFAULT_ALL) //priority 优先权 //优先权设置成最高,但是没有出现预期的弹出效果 .setPriority(NotificationCompat.PRIORITY_MAX) .build(); notificationManager.notify(1, notification); } }); }}
阅读全文
0 0
- Andriod Notification
- Andriod Notification的使用
- andriod Notification area/drawer
- andriod
- andriod
- Andriod
- andriod
- andriod
- Andriod
- Andriod
- Andriod
- Notification
- Notification
- Notification
- Notification
- notification
- Notification
- Notification
- 2017/12/7
- jQuery学习第一节
- 剑指offer 试题21~30
- python-lxml的demo
- 多径数据流的数据包调度
- Andriod Notification
- 1007. 素数对猜想 (20)
- 莫名奇妙的异常001:Invalid or unexpected token
- ORA-12519错误的解决方案
- 3D 可视手写数字CNN识别
- MapReduce代码实现1
- JDK 源码解析 —— Integer
- js-解决echarts在使用tab情况下现实不全的问题
- xmind教程