notification几种点击事件

更新时间:2023-07-25 15:59:21 阅读: 评论:0

notification⼏种点击事件
notification :以另⼀种UI界⾯形式展⽰出来,点击时可以对其应⽤做处理。
pgl
其常⽤的⼀些基本属性: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以上版本的模拟器,以下容易出错。)
daffy<activity android:name="ample.ui.widget.Marquee_Test"              <!-- 记住应在跳转界⾯下注册其⽗类 -->
android:parentActivityName="ample.layout.LayoutAll">  <!-- 1、注册⽅式⼀⽀持4.1以上版本 -->
sounds是什么意思<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
.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); //⾃定义布局
commodorebuilder.tContent(view);
Intent playIntent = new Intent(NotifyActivity.this,
PlayMusicService.class);    //启动服务
playIntent.tAction("1");
职称英语论坛
playIntent.putExtra(
ideo
"PATH","file://"+ ExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
+ "/wy.mp3");
playIntent.putExtra("FLAG", 1);
PendingIntent playPending = Service(
NotifyActivity.this, 0, playIntent,parasite
PendingIntent.FLAG_UPDATE_CURRENT);
view.tOnClickPendingIntent(R.id.music_play_img, playPending);  //设置监听事件
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

本文发布于:2023-07-25 15:59:21,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/188430.html

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

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