notification几种点击事件

更新时间:2023-07-17 13:35:00 阅读: 评论:0

notification⼏种点击事件
notification :以另⼀种UI界⾯形式展⽰出来,点击时可以对其应⽤做处理。
其常⽤的⼀些基本属性:tSmallIcon()设置图标  、tContentTitle()设置题⽬、tContentText()设置内容、tAutoCancel()设置点击后是否⾃动销毁、tTicker()设置通知时的滚动⽂本
1、构造通知、跳转界⾯
// 构造通知界⾯
NotificationCompat.Builder builder = new NotificationCompat.Builder(
NotifyActivity.this);
builder.tSmallIcon(R.drawable.ic_launcher)
.tContentTitle(getString(R.string.hello_world))
白萝卜的营养价值.tContentText(getString(R.string.hint_text))
.tAutoCancel(true) // 点击跳转后⾃动销毁
.tTicker(getString(R.string.hello_world)); // 设置滚动⽂本
感冒有啥症状
// 通知⾏为(点击后能进⼊应⽤界⾯)
Intent intent = new Intent(NotifyActivity.this,
Marquee_Test.class);
PendingIntent pendingIntent = Activity(
NotifyActivity.this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.tContentIntent(pendingIntent);
// 发送通知
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
2、导航功能,返回应⽤⾸页
怎么去除牙垢此时若点击返回时则直接跳出应⽤,若想其不退出应⽤还应在manifest中注册其⽗类路径(尽量使⽤4.1以上版本的模拟器,以下容易出错。)
<activity android:name="ample.ui.widget.Marquee_Test"              <!-- 记住应在跳转界⾯下注册其⽗类 -->
android:parentActivityName="ample.layout.LayoutAll">  <!-- 1、注册⽅式⼀⽀持4.1以上版本 -->
<meta-data  android:name= "android.support.PARENT_ACTIVITY"<!-- 2、注册⽅式⼆ -->
android:value="ample.layout.LayoutAll"  />
蒙嘉慧
</activity>
此时只改变上⽅通知⾏为部分即可
<span >    </span>Intent intent = new Intent(NotifyActivity.this,
Marquee_Test.class);          //要跳转的界⾯
TaskStackBuilder taskStackBuilder = TaskStackBuilder
wps表格教程.create(NotifyActivity.this);
taskStackBuilder.addParentStack(Marquee_Test.class);    //参数为跳转界⾯
taskStackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = taskStackBuilder
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.tContentIntent(pendingIntent);
3、BigView 系统按钮监听事件
此时也只⽤改变上⽅通知⾏为部分即可
<span >    </span>//播放部分
<span >    </span>Intent playIntent = new Intent(NotifyActivity.this,
PlayMusicService.class);
playIntent.tAction("1");
playIntent.putExtra(
"PATH","file://"+ ExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
+ "/wy.mp3");
playIntent.putExtra("FLAG", 1);
PendingIntent playPending = Service(
NotifyActivity.this, 0, playIntent,
天津教育局电话
PendingIntent.FLAG_UPDATE_CURRENT);
<span >    </span>//暂停部分
Intent pauIntent = new Intent(NotifyActivity.this,
PlayMusicService.class);
pauIntent.putExtra("PATH","file://"+ Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)+ "/wy.mp3");        //将播放⽂件传递到服务端    pauIntent.tAction("2");  //此时必须设置action,不然不能播放,单个控件时可以不⽤设置,参数⾃定义
pauIntent.putExtra("FLAG", 2);        //判断播放、暂停标记
PendingIntent pauPending = Service(兴致勃勃拼音
NotifyActivity.this, 0, pauIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(R.drawable.bg_actionbar, "播放", playPending);  //系统添加按钮控件
builder.addAction(R.drawable.bg_actionbar, "暂停", pauPending);
4、⾃定义通知界⾯
<span >    </span>NotificationCompat.Builder builder = new NotificationCompat.Builder(
NotifyActivity.this);
builder.tSmallIcon(R.drawable.ic_launcher);  //此条件必须设置,不然不能显⽰
builder.tTicker("开始播放⾳乐");
RemoteViews view = new RemoteViews(getPackageName(), ify_play_music_layout); //⾃定义布局
周杰伦青花瓷
builder.tContent(view);
Intent playIntent = new Intent(NotifyActivity.this,
PlayMusicService.class);    //启动服务
playIntent.tAction("1");
playIntent.putExtra(
"PATH","file://"+ ExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
+ "/wy.mp3");
playIntent.putExtra("FLAG", 1);
PendingIntent playPending = Service(
NotifyActivity.this, 0, playIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
view.tOnClickPendingIntent(R.id.music_play_img, playPending);  //设置监听事件
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

本文发布于:2023-07-17 13:35:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1085114.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:设置   通知   点击   播放   跳转   模拟器   返回
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图