光播的一些属性设置
2015-12-28 16:21
225 查看
public class LocalReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "我是本地广播接受者", 3).show();
Log.i("name", intent.getStringExtra("name"));
// 通过发送广播来通知,光播如果做耗时操作一般会开启服务
NotificationManager manager = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
Intent intent2 = new Intent(context, ShowActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent2, 0);
RemoteViews rviews = new RemoteViews(context.getPackageName(),
R.layout.mynotification);
rviews.setImageViewResource(R.id.iv, R.drawable.clothing_0108);
rviews.setTextViewText(R.id.tv, "我自定义的啊");
// 声音
File mediaPathFile = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/tiankong.mp3");
Uri soundUri = Uri.fromFile(mediaPathFile);
Notification notification = new Notification.Builder(context)
.setContent(rviews)
// 设置自定义通知界面
.setTicker("未读消息提示")
.setContentText("我是消息内容")
.setContentTitle("我是消息标题")
.setSmallIcon(R.drawable.ic_launcher)
.setLights(Color.RED, 1000, 1000)
.setSound(soundUri)
.setVibrate(
new long[] { 0, 2000, 1000, 2000, 1000, 2000, 1000 })
.setWhen(new Date().getTime()).setContentIntent(pi).build();
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
// 点击后,自动取消
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// 管理器发送
manager.notify(1, notification);
}
}
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "我是本地广播接受者", 3).show();
Log.i("name", intent.getStringExtra("name"));
// 通过发送广播来通知,光播如果做耗时操作一般会开启服务
NotificationManager manager = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
Intent intent2 = new Intent(context, ShowActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 0, intent2, 0);
RemoteViews rviews = new RemoteViews(context.getPackageName(),
R.layout.mynotification);
rviews.setImageViewResource(R.id.iv, R.drawable.clothing_0108);
rviews.setTextViewText(R.id.tv, "我自定义的啊");
// 声音
File mediaPathFile = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/tiankong.mp3");
Uri soundUri = Uri.fromFile(mediaPathFile);
Notification notification = new Notification.Builder(context)
.setContent(rviews)
// 设置自定义通知界面
.setTicker("未读消息提示")
.setContentText("我是消息内容")
.setContentTitle("我是消息标题")
.setSmallIcon(R.drawable.ic_launcher)
.setLights(Color.RED, 1000, 1000)
.setSound(soundUri)
.setVibrate(
new long[] { 0, 2000, 1000, 2000, 1000, 2000, 1000 })
.setWhen(new Date().getTime()).setContentIntent(pi).build();
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
// 点击后,自动取消
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// 管理器发送
manager.notify(1, notification);
}
}
相关文章推荐
- C/Cpp指针
- 一个正则表达式测试(只可输入中文、字母和数字)
- snack程序设计
- 正则表达式语法
- data factory快速生成大批量数据
- 【JavaScript 从零开始】 数字 文本 包装对象
- 解决MYSQL数据库 Table ‘xxx’ is marked as crashed and should be repaired 145错误
- 【转】lettuce介绍
- 老李分享:Android性能优化之内存泄漏 2
- 保留2位小数
- 老李分享:Android性能优化之内存泄漏 1
- Android安装APK报错:Installation error: INSTALL_FAILED_UPDATE_INCOMPATIBLE解决方法
- windows 10 markdown pad awesomium crashed
- WSAWaitForMultipleEvents
- [leetcode] 278. First Bad Version 解题报告
- oracle实现夸多个数据查询
- js异步编程技巧一
- mysql触发器
- Python调用C/C++动态链接库的方法
- 手机自动化测试:Appium源码分析之跟踪代码分析九 2