public class MyBroadCastReceiver extends BroadcastReceiver {

@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String string = intent.getStringExtra("msg");
Toast.makeText(context, string, 0).show();
NotificationManager manager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);

Intent intent2 = new Intent(context, MainActivity.class);
intent2.putExtra("NOTICE", true);

intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent2, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(R.drawable.ic_launcher,
"通知未打开显示的标题", System.currentTimeMillis());
notification.setLatestEventInfo(context.getApplicationContext(),
"通知的标题", "通知的内容" + string, pendingIntent);
AudioManager mAudioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);

notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_LIGHTS
| Notification.DEFAULT_VIBRATE;
notification.sound = Uri.parse("android.resource://"
+ context.getPackageName() + "/" + R.raw.newdatatoast);
manager.notify(0, notification);
}
}

更多相关文章

  1. Android通知权限设置(8.0上下兼容)
  2. android检测wifi是否打开或连接及设置自动打开
  3. Android(安卓)打开状态栏 EXPAND_STATUS_BAR
  4. 【notification】Android(安卓)中创建状态栏通知
  5. android之视频播放控件VideoView简单应用
  6. Android(安卓)打开手电筒
  7. Android(安卓)调用浏览器,打开网页
  8. Android(安卓)Studio 打造一个适合自己开发环境-- Distraction F
  9. android 状态栏显示运行图标

随机推荐

  1. 超级菜鸟怎么学习数据分析
  2. RFM分析-用户价值细分的精准运营方法
  3. 综合指标分析法
  4. 不可不知的分组分析法
  5. 视频讲解 | 图解剑指offer:二维数组的查找
  6. 对比Excel学习SQL(4):计算字段
  7. 对比Excel学习SQL(6):表连接
  8. 分析的基础:平均和交叉的思路
  9. 确保网站性能的5个小贴士
  10. LeetCode 题解 | 1297.子串的最大出现次