@Override protected void onDestroy() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon; CharSequence tickerText = getResources().getString(R.string.ministro_repository_changed_msg); // ticker-text long when = System.currentTimeMillis(); // notification time Context context = getApplicationContext(); // application Context CharSequence contentTitle = getResources().getString(R.string.ministro_update_msg); // expanded message title CharSequence contentText = getResources() .getString(R.string.ministro_repository_changed_tap_msg); // expanded message text Intent notificationIntent = new Intent(this, MinistroActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); // the next two lines initialize the Notification, using the configurations above Notification notification = new Notification(icon, tickerText, when); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; try { nm.notify(1, notification); } catch (Exception e) { e.printStackTrace(); } super.onDestroy(); }
@Override public void handleMessage(Message msg) { switch (msg.what) { case DOWNLOAD_COMPLETE: // 点击安装PendingIntent Uri uri = Uri.fromFile(updateFile); Intent installIntent = new Intent(Intent.ACTION_VIEW); installIntent.setDataAndType(uri, "application/vnd.android.package-archive"); updatePendingIntent = PendingIntent.getActivity(AppUpdateService.this, 0, installIntent, 0); updateNotification.defaults = Notification.DEFAULT_SOUND; // 铃声提醒 updateNotification.setLatestEventInfo( AppUpdateService.this, appName_cn, "下载完成,点击安装。", updatePendingIntent); updateNotificationManager.notify(0, updateNotification); // 停止服务 stopSelf(); break; case DOWNLOAD_FAIL: // 下载失败 updateNotification.setLatestEventInfo( AppUpdateService.this, ConstantStrUtil.APP_NAME, "下载完成,点击安装。", updatePendingIntent); updateNotificationManager.notify(0, updateNotification); break; default: stopSelf(); } }
/** * This method sends a notification to NotificationManager to display an error dialog indicating * low disk space and launch the Installer application */ private final void sendNotification() { if (localLOGV) Slog.i(TAG, "Sending low memory notification"); // log the event to event log with the amount of free storage(in bytes) left on the device EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem); // Pack up the values and broadcast them to everyone Intent lowMemIntent = new Intent( Environment.isExternalStorageEmulated() ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS : Intent.ACTION_MANAGE_PACKAGE_STORAGE); lowMemIntent.putExtra("memory", mFreeMem); lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); NotificationManager mNotificationMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence title = mContext.getText(com.android.internal.R.string.low_internal_storage_view_title); CharSequence details = mContext.getText(com.android.internal.R.string.low_internal_storage_view_text); PendingIntent intent = PendingIntent.getActivityAsUser(mContext, 0, lowMemIntent, 0, null, UserHandle.CURRENT); Notification notification = new Notification(); notification.icon = com.android.internal.R.drawable.stat_notify_disk_full; notification.tickerText = title; notification.flags |= Notification.FLAG_NO_CLEAR; notification.setLatestEventInfo(mContext, title, details, intent); mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL); mContext.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL); }
/** Issues a notification to inform the user that server has sent a message. */ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Play default notification sound notification.defaults |= Notification.DEFAULT_SOUND; // notification.sound = Uri.parse("android.resource://" + context.getPackageName() + // "your_sound_file_name.mp3"); // Vibrate if vibrate is enabled notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification); }
public boolean isThisDeviceAlreadyRegisteredWithPrey(boolean notifyUser) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ctx); String deviceId = settings.getString(PreyConfig.PREFS_DEVICE_ID, null); boolean isVerified = deviceId != null; if (notifyUser && !isVerified) { String notificationTitle = ctx.getText(R.string.not_verified_device_title).toString(); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification( R.drawable.ic_stat_notify_exclamation25, notificationTitle, System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; Intent preyMainActivity = new Intent(ctx, WelcomeActivity.class); String notificationToShow = ctx.getText(R.string.not_verified_device_msg).toString(); PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, preyMainActivity, 0); notification.contentIntent = contentIntent; notification.setLatestEventInfo( ctx, ctx.getText(R.string.not_verified_device_title), notificationToShow, contentIntent); nm.notify(R.string.preyForAndroid_name, notification); } return isVerified; }
private void showNotification(String title, String note, boolean isTaskComplete) { Notification notification = new Notification(R.drawable.liltomato, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_ONGOING_EVENT; if (isTaskComplete) { notification = new Notification(R.drawable.liltomato_red, null, System.currentTimeMillis()); notification.flags = Notification.FLAG_ONGOING_EVENT; String ringtone = taskDatabaseMap.getPreferences().getRingtone(); if (ringtone == null) { ringtone = "android.resource://" + getApplication().getPackageName() + "/" + R.raw.freesoundprojectdotorg_32568__erh__indian_brass_pestle; } notification.sound = Uri.parse(ringtone); if (taskDatabaseMap.getPreferences().notifyPhoneVibrate()) { notification.vibrate = new long[] {0, 100, 200, 300}; } notification.tickerText = title; notification.defaults |= Notification.DEFAULT_LIGHTS; } PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TaskBrowserActivity.class), 0); notification.setLatestEventInfo(this, title, note, contentIntent); notificationManager.notify(NOTIFICATION_ID, notification); }
public void makeNotification( String title, String content, int extraNotificationFlag, Intent intent) { int notificationId = 0; int notificationIcon = 0; if ((extraNotificationFlag & Notification.FLAG_ONGOING_EVENT) != 0) { notificationIcon = R.drawable.icon; notificationId = ON_GOING_NOTIFICATION_ID; } else { notificationIcon = R.drawable.message_sent; notificationId = NOTIFICATION_ID; if (++NOTIFICATION_ID > MAX_NOTIFICATION_ID) { NOTIFICATION_ID = INIT_NOTIFICATION_ID; } } Notification newNotification = new Notification(notificationIcon, content, System.currentTimeMillis()); newNotification.flags = newNotification.flags | extraNotificationFlag; // start the passer activity to cancel the notification PendingIntent correspondingIntent = PendingIntent.getActivity(context, 0, intent, 0); newNotification.setLatestEventInfo(context, title, content, correspondingIntent); notificationManager.notify(notificationId, newNotification); }
// 在状态栏提示分享操作 private void showNotification(long cancelTime, String text) { try { Context app = getContext().getApplicationContext(); NotificationManager nm = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE); final int id = Integer.MAX_VALUE / 13 + 1; nm.cancel(id); long when = System.currentTimeMillis(); Notification notification = new Notification(notifyIcon, text, when); PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(), 0); notification.setLatestEventInfo(app, notifyTitle, text, pi); notification.flags = Notification.FLAG_AUTO_CANCEL; nm.notify(id, notification); if (cancelTime > 0) { Message msg = new Message(); msg.what = MSG_CANCEL_NOTIFY; msg.obj = nm; msg.arg1 = id; UIHandler.sendMessageDelayed(msg, cancelTime, this); } } catch (Exception e) { e.printStackTrace(); } }
@Override public void onFail(DownloadTask task) throws RemoteException { // TODO Auto-generated method stub if (mContext != null && task != null) { if (mNotificationManager != null) { // 移除之前的通知 mNotificationManager.cancel(NOTIFY_TAG, (int) task.getId()); // 更新下载信息 if (mShowNotification && mNotification != null) { mNotification.tickerText = mFailTickerText; mNotification.contentIntent = mPendingIntent; // mNotificationRemoteViews.setTextViewText(R.id.downloadTextView, mFailText); // mNotification.contentView = mNotificationRemoteViews; mNotification.setLatestEventInfo( mContext, mFailText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); mNotification.flags = Notification.FLAG_AUTO_CANCEL; // mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } } } }
/** 作用:推送通知(带参) */ public static void sendNotification( Context context, String title, String message, Class<?> activity, String url, String json) { // 定义NotificationManager NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // 定义通知栏展现的内容信息 Notification notification = new Notification(R.drawable.ic_launcher, title, System.currentTimeMillis()); // 点击后跳传的activity Intent notificationIntent = new Intent(context, activity); notificationIntent .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra("notification", 1) .putExtra("url", url) .putExtra("json", json) .putExtra("back", 0); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT); // 设置默认提示音 notification.defaults |= Notification.DEFAULT_SOUND; // 点击后自动取消通知 notification.flags = Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, title, message, contentIntent); // 用mNotificationManager的notify方法通知用户生成标题栏消息通知 mNotificationManager.notify(1, notification); // St.onEvent(context, "通过推送启动App", message, url); // 统计---------------------------- }
@Override protected void onMessage(Context arg0, Intent i) { String tvid = i.getStringExtra("tvid"); Log.i("Message Received", tvid); String rtitle = i.getStringExtra("title"); Log.i("Message Received", rtitle); String status = i.getStringExtra("status"); Log.i("Message Received", status); String rely = i.getStringExtra("rely"); Log.i("Message Received", rely); String epname = i.getStringExtra("epname"); Log.i("Message Received", epname); String epinfo = i.getStringExtra("epinfo"); Log.i("Message Received", epinfo); String epdate = i.getStringExtra("epdate"); Log.i("Message Received", epdate); Databasehelper dbh = new Databasehelper(this); dbh.update(tvid, rtitle, status, rely, epname, epinfo, epdate); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); intent = new Intent(this, ShowSeries.class); PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); String body = tvid; String title = "Message Received"; Notification n = new Notification(R.drawable.ic_launcher, body, System.currentTimeMillis()); n.setLatestEventInfo(getApplicationContext(), title, body, pi); n.defaults = Notification.DEFAULT_ALL; n.flags = Notification.FLAG_AUTO_CANCEL; nm.notify(NotifyId, n); }
@SuppressWarnings("static-access") @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); mManager = (NotificationManager) this.getApplicationContext() .getSystemService(this.getApplicationContext().NOTIFICATION_SERVICE); Intent intent1 = new Intent(this.getApplicationContext(), MainActivity.class); Notification notification = new Notification( R.drawable.ic_launcher, "This is a test message!", System.currentTimeMillis()); intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingNotificationIntent = PendingIntent.getActivity( this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_UPDATE_CURRENT); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo( this.getApplicationContext(), "AlarmManagerDemo", "This is a test message!", pendingNotificationIntent); mManager.notify(0, notification); }
@SuppressWarnings("deprecation") @Override public int onStartCommand(Intent intent, int flags, int startId) { nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification = new Notification(); notification.icon = android.R.drawable.stat_sys_download; // notification.icon=android.R.drawable.stat_sys_download_done; notification.tickerText = getString(R.string.app_name) + "下载"; notification.when = System.currentTimeMillis(); notification.defaults = Notification.DEFAULT_LIGHTS; // 设置任务栏中下载进程显示的views views = new RemoteViews(getPackageName(), R.layout.version_update); notification.contentView = views; PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.setLatestEventInfo(this, "", "", contentIntent); // 将下载任务添加到任务栏中 nm.notify(notificationId, notification); myHandler = new MyHandler(Looper.myLooper(), this); // 初始化下载任务内容views Message message = myHandler.obtainMessage(3, 0); myHandler.sendMessage(message); // 启动线程�?��执行下载任务 downFile(intent.getStringExtra("url")); return super.onStartCommand(intent, flags, startId); }
private void showNotificationExr( Context context, int statusBarIconID, String string, boolean showIconOnly) { // This is who should be launched if the user selects our notification. Intent contentIntent = new Intent(context, WelbingActivityExercise.class); Intent targetIntent = new Intent(context, WellbeingExReminderAlert.class); targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // choose the ticker text String tickerText = "Seva60Plus"; Notification n = new Notification(R.drawable.icon, "Seva60Plus", System.currentTimeMillis()); PendingIntent appIntent = PendingIntent.getActivity(context, 0, contentIntent, 0); n.setLatestEventInfo(context, "WELBING", "DID YOU EXERCISE TODAY ?", appIntent); // n.sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + // "://com.seva60plus.seva60plus/raw/ex_sound"); n.defaults |= Notification.DEFAULT_LIGHTS; n.flags |= Notification.FLAG_AUTO_CANCEL; n.flags |= Notification.FLAG_INSISTENT; long[] vibrate = {0, 500, 500, 500}; n.vibrate = vibrate; // mNotificationManager.notify(YOURAPP_NOTIFICATION_ID, n); context.startActivity(targetIntent); }
public void onCreate() { contentTitle = this.getString(R.string.app_name); updateTitleRunnable = new UpdateTitleRunnable(mHandler, this.getString(R.string.radiouid)); // notification stuff String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon_small = R.drawable.icon_small; CharSequence tickerText = this.getString(R.string.app_name); long when = System.currentTimeMillis(); notification = new Notification(icon_small, tickerText, when); notificationIntent = new Intent(this, PlayerActivity.class); // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.setLatestEventInfo(getApplicationContext(), contentTitle, "", contentIntent); notification.flags = Notification.FLAG_NO_CLEAR; mNotificationManager.notify(1, notification); super.onCreate(); this.loadPlaylist(); // listen to states of the phone (to put on pause when calling, etc.) TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); new Thread(updateTitleRunnable, "updateTitleThreadInService").start(); }
/** * Notificationを更新する * * @param changedState 変化後の状態 */ private void updateNotification(int changedState) { switch (changedState) { case MSG_MEDIA_PLAY_SERVICE_PLAY_STARTED: { // Android 2.2以下と2.3以上でステータスバーに表示するアイコンを分ける final int iconId = ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) ? R.drawable.ic_stat_2_3 : R.drawable.ic_stat_2_2); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification n = new Notification(iconId, mNotificationTitle, System.currentTimeMillis()); Intent intent = new Intent(this, ChannelActivity.class); intent.putExtra(ChannelActivity.INTENT_EXTRA_OPEN_CHANNEL_PLAY_URL, mPlayingPath); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); n.setLatestEventInfo(this, mNotificationTitle, mNotificationContent, contentIntent); nm.notify(C.NOTIFICATION_ID, n); break; } case MSG_MEDIA_PLAY_SERVICE_PREPARE_STARTED: case MSG_MEDIA_PLAY_SERVICE_PLAY_COMPLATED: case MSG_MEDIA_PLAY_SERVICE_PLAY_STOPPED: case MSG_MEDIA_PLAY_SERVICE_FAILD_PLAY_START: // 再生中ではないのでNotificationを消す NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.cancel(C.NOTIFICATION_ID); break; default: break; } }
public void createNotification() { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notification = new Notification(); notification.icon = R.drawable.ic_launcher; // // 这个参数是通知提示闪出来的值. notification.tickerText = "开始下载"; // updateIntent = new Intent(this, MainActivity.class); pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0); // // // 这里面的参数是通知栏view显示的内容 notification.setLatestEventInfo(this, app_name, "下载:0%", pendingIntent); // notificationManager.notify(notification_id, notification); /** * 在这里我们用自定的view来显示Notification */ contentView = new RemoteViews(getPackageName(), R.layout.notification_item); contentView.setTextViewText(R.id.notificationTitle, "正在下载"); contentView.setTextViewText(R.id.notificationPercent, "0%"); contentView.setProgressBar(R.id.notificationProgress, 100, 0, false); notification.contentView = contentView; updateIntent = new Intent(this, MainActivity.class); updateIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0); notification.contentIntent = pendingIntent; notificationManager.notify(notification_id, notification); }
private static void startNotification() { Intent i = new Intent(context, SalatTimes.class); notification.setLatestEventInfo( context, context.getString(R.string.app_name), notification.tickerText, PendingIntent.getActivity( context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT)); notification.contentIntent = PendingIntent.getBroadcast( context, 0, new Intent(context, ClickNotificationReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); notification.deleteIntent = PendingIntent.getBroadcast( context, 0, new Intent(context, ClearNotificationReceiver.class), PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)) .notify(1, notification); if (mediaPlayer == null || !mediaPlayer.isPlaying()) { try { Thread.sleep(CONSTANT.POST_NOTIFICATION_DELAY); } catch (Exception ex) { // Just trying to make sure the notification completes before we fall asleep again } WakeLock.release(); } }
@SuppressWarnings("deprecation") @Override public void onReceive(Context ctxt, Intent intent) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt); boolean useNotification = prefs.getBoolean("use_notification", true); if (useNotification) { NotificationManager mgr = (NotificationManager) ctxt.getSystemService(Context.NOTIFICATION_SERVICE); Notification note = new Notification( android.R.drawable.stat_notify_chat, "It's time for lunch!", System.currentTimeMillis()); PendingIntent i = PendingIntent.getActivity(ctxt, 0, new Intent(ctxt, AlarmActivity.class), 0); note.setLatestEventInfo(ctxt, "LunchList", "It's time for lunch! Aren't you hungry?", i); note.flags |= Notification.FLAG_AUTO_CANCEL; mgr.notify(NOTIFY_ME_ID, note); } else { Intent i = new Intent(ctxt, AlarmActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ctxt.startActivity(i); } }
private void handleMessage(final Context context, Intent intent) { // push를 사용 안할 경우 메시지가 오더라도 무시 함. SharedPreferences preferences = context.getSharedPreferences("pushPref", Activity.MODE_PRIVATE); boolean isPushEnable = preferences.getBoolean("isPushEnable", true); if (!isPushEnable) { Logger.d("handleMessage", "isPushEnable : " + isPushEnable); return; } // 화면을 켬 pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); wl = pm.newWakeLock( PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "bbbb"); wl.acquire(); Log.i("handleMessage", "------------ COME MESSAGE: " + pushKey); // TODO Auto-generated method stub String count = intent.getExtras().getString("badge"); String message = intent.getExtras().getString("message"); // String collaspe_key = intent.getExtras().getString("collaspe_key"); Log.i("handleMessage", "------------ COME MESSAGE: " + message + ", " + count); Notification notification = new Notification( RUtil.getDrawableR(context, "app_icon"), message, System.currentTimeMillis()); // notiId int notiID = (int) System.currentTimeMillis(); // TODO 현재는 시작 화면으로 가게 했지만 추후 수정해야함. String title = PushManager.getInstance().getNotiMessage(PushManager.MESSAGE_TITLE); Intent in = new Intent(Intent.ACTION_MAIN); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.addCategory(Intent.CATEGORY_LAUNCHER); in.setComponent(new ComponentName(context, DummyActivity.class)); in.putExtra("push", message); in.putExtra("push_noti_id", notiID); PendingIntent pi = PendingIntent.getActivity( context, notiID, in, Intent.FLAG_ACTIVITY_NEW_TASK | PendingIntent.FLAG_ONE_SHOT); notification.setLatestEventInfo(context, title, message, pi); notification.flags |= Notification.FLAG_AUTO_CANCEL; // 선택시 자동삭제 NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); // 전체 제거 고려 if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { notification.defaults |= android.app.Notification.DEFAULT_SOUND; } else { // 진동 효과 구성 long[] vibrate = {1000, 1000, 1000, 1000, 1000}; notification.vibrate = vibrate; } // nm.notify(PushManager.PUSH_MESSAGE, notification); nm.notify(notiID, notification); run.run(); }
// 通知センターに通知を残す(pecoriできる人がいます) private void notifyNearUser(HttpResponse res) throws Exception { String body = EntityUtils.toString(res.getEntity(), "UTF-8"); JSONObject json = new JSONObject(body.toString()); JSONArray nearUsers = json.getJSONArray("near_users"); for (int i = 0; i < nearUsers.length(); i++) { JSONObject user = nearUsers.getJSONObject(i); String facebookId = user.getString("facebook_id"); String name = user.getString("name"); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification( android.R.drawable.btn_default, "近くに" + name + "さんがいるようです。", System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; // Notificationが選択された場合のIntent Intent intent = new Intent(Intent.ACTION_VIEW); PendingIntent contentIntent = PendingIntent.getActivity(LocationDetectService.this, 0, intent, 0); notification.setLatestEventInfo( getApplicationContext(), "Pecori", "近くに" + name + "さんがいるようです。", contentIntent); notificationManager.notify(R.string.app_name, notification); } }
@Override public void onCreate() { HunyDewZLogger.startTrace("fulfillerf"); super.onCreate(); fulfillerLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationListener fulfillerLocListener = new HunyDooLocationListener(); // if (LocationManager.GPS_PROVIDER!=null) // hdLocProvider = LocationManager.GPS_PROVIDER; Criteria hdCrit = new Criteria(); hdCrit.setAccuracy(Criteria.ACCURACY_COARSE); hdLocProvider = fulfillerLocManager.getBestProvider(hdCrit, true); // ms // meter fulfillerLocManager.requestLocationUpdates(hdLocProvider, 60000, 100, fulfillerLocListener); // Location currentLocation = fulfillerLocManager.getLastKnownLocation(hdLocProvider); // Instantiate the notification int iconReached = R.drawable.push_pin; // TBD - eventually this will be small size launcher Icon String textReachedLoca = getResources().getText(R.string.notiMesg).toString(); long whenReached = System.currentTimeMillis(); hdLocaReachedNotification = new Notification(iconReached, textReachedLoca, whenReached); hdLocaReachedNotification.defaults |= Notification.DEFAULT_SOUND; hdLocaReachedNotification.defaults |= Notification.DEFAULT_LIGHTS; hdLocaReachedNotification.defaults |= Notification.DEFAULT_VIBRATE; hdLocaReachedNotification.audioStreamType = AudioManager.STREAM_NOTIFICATION; // Repeat audio until the user responds hdLocaReachedNotification.flags |= Notification.FLAG_INSISTENT; // Flashing Lights hdLocaReachedNotification.ledARGB = 0xff00ff00; hdLocaReachedNotification.ledOnMS = 300; hdLocaReachedNotification.ledOffMS = 1000; hdLocaReachedNotification.flags |= Notification.FLAG_SHOW_LIGHTS; // define the notification's expanded message and intent CharSequence contentTitle = getResources().getText(R.string.notiTitle); CharSequence contentText = getResources().getText(R.string.notiMesg); Intent notificationIntent = new Intent(this, HunyDewAAStartsHere.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); hdLocaReachedNotification.setLatestEventInfo( getApplicationContext(), contentTitle, contentText, contentIntent); // now start the service startFulfillerService(); if (MAIN_ACTIVITY != null) { Log.i(getClass().getSimpleName(), "MyService Started"); } }
@Override public void onStop(DownloadTask task) throws RemoteException { if (mNotificationManager != null && mNotification != null) { mNotification.tickerText = mStopTickerText; mNotification.flags = Notification.FLAG_AUTO_CANCEL; mNotification.contentIntent = mPendingIntent; // if (RecommAppsUtils.isZh()) { mNotification.setLatestEventInfo( mContext, mPauseText, mProgressText + " " + task.getAlreadyDownloadPercent() + "%", mPendingIntent); // } else { // mNotification.setLatestEventInfo(mContext, mPauseText, // task.getAlreadyDownloadPercent() + "%", // mPendingIntent); // } // mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); if (mNotification.contentView != null) { mNotificationManager.notify(NOTIFY_TAG, (int) task.getId(), mNotification); } } if (task != null) { // add by xiedezhi sendBroadcastingToAppCenter(task); } }
@Override void doReminderWork(Intent intent) { Log.d("ReminderService", "Doing work."); Long rowId = intent.getExtras().getLong(RemindersDbAdapter.KEY_ROWID); NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(this, ReminderEditActivity.class); notificationIntent.putExtra(RemindersDbAdapter.KEY_ROWID, rowId); PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification note = new Notification( android.R.drawable.ic_menu_my_calendar, getString(R.string.notify_new_task_message), System.currentTimeMillis()); note.setLatestEventInfo( this, getString(R.string.notify_new_task_title), getString(R.string.notify_new_task_message), pi); note.defaults |= Notification.DEFAULT_SOUND; note.defaults |= Notification.DEFAULT_VIBRATE; note.flags |= Notification.FLAG_AUTO_CANCEL; // An issue could occur if user ever enters over 2,147,483,647 tasks. (Max int value). // I highly doubt this will ever happen. But is good to note. int id = (int) ((long) rowId); mgr.notify(id, note); }
/** * generate chat notification * * @param context * @param message * @param userId */ @SuppressWarnings("deprecation") public void generateNotification( Context context, String message, String fullname, String userImage, String userId) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = null; notificationIntent = new Intent(context, ChatActivity.class); notificationIntent.putExtra("fullname", fullname); notificationIntent.putExtra("user_id", userId); notificationIntent.putExtra("image", userImage); PendingIntent intent = PendingIntent.getActivity( context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Play default notification sound notification.defaults |= Notification.DEFAULT_SOUND; // Vibrate if vibrate is enabled notification.defaults |= Notification.DEFAULT_VIBRATE; notificationManager.notify(0, notification); }
private void showNotification(ArrayList<String> list, int flag) { String titleText = ""; if (list.isEmpty()) { return; } else { switch (flag) { case -1: titleText = "¡Tienes recocordatorios atrasados!"; break; case 0: titleText = "¡Tienes recocordatorios hoy!"; break; } String contentText = "Recocordatorios: "; for (String s : list) { contentText = contentText.concat(s); contentText = contentText.concat(", "); } Notification notification = new Notification(R.drawable.icon, titleText, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MemoryCoconutActivity.class), 0); notification.setLatestEventInfo(this, titleText, contentText, contentIntent); mNM.notify(flag, notification); } }
private void updateNotification(Context context, Alarm alarm, int timeout) { NotificationManager nm = getNotificationManager(context); // If the alarm is null, just cancel the notification. if (alarm == null) { if (Log.LOGV) { Log.v("Cannot update notification for killer callback"); } return; } // Launch SetAlarm when clicked. Intent viewAlarm = new Intent(context, SetAlarm.class); viewAlarm.putExtra(Alarms.ALARM_ID, alarm.id); PendingIntent intent = PendingIntent.getActivity(context, alarm.id, viewAlarm, 0); // Update the notification to indicate that the alert has been // silenced. String label = alarm.getLabelOrDefault(context); Notification n = new Notification(R.drawable.stat_notify_alarm, label, alarm.time); n.setLatestEventInfo( context, label, context.getString(R.string.alarm_alert_alert_silenced, timeout), intent); n.flags |= Notification.FLAG_AUTO_CANCEL; // We have to cancel the original notification since it is in the // ongoing section and we want the "killed" notification to be a plain // notification. nm.cancel(alarm.id); nm.notify(alarm.id, n); }
// Notification public void showStartNotification() { notification.flags = Notification.FLAG_ONGOING_EVENT; notification.setLatestEventInfo( this, getString(R.string.app_name), getString(R.string.qaul_running), this.mainIntent); this.notificationManager.notify(-1, this.notification); }
public void tampilkanNotifikasiPeringatan(Peringatan peringatan) { int icon = R.drawable.pelanggaran; CharSequence tickerText = ""; CharSequence contentTitle = ""; long when = System.currentTimeMillis(); DatabaseManagerOrtu databaseManager = new DatabaseManagerOrtu(context); DataMonitoring dataMonitoring = databaseManager.getDataMonitoringByIdMonitoring(peringatan.getIdMonitoring(), true, true); Anak anak = dataMonitoring.getAnak(); if (peringatan.getTipe() == TipePesanMonak.PERINGATAN_TERLARANG) { tickerText = anak.getNamaAnak() + " melakukan pelanggaran..." + "!!!PERINGATAN TERLARANG" + "!!!"; contentTitle = "PERINGATAN TERLARANG"; } else { tickerText = anak.getNamaAnak() + " melakukan pelanggaran..." + "!!!PERINGATAN SEHARUSNYA" + "!!!"; contentTitle = "PERINGATAN SEHARUSNYA"; } Notification notification = new Notification(icon, tickerText, when); CharSequence contentText = "anak : " + anak.getNamaAnak() + "\n" + "click disini untuk lihat lokasi"; Intent notificationIntent = new Intent(context, Peta.class); notificationIntent.putExtra(Peta.EXTRA_ACTION, Peta.EXTRA_PELANGGARAN); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(PELANGGARAN_NOTIFIKASI, notification); }
/** Notify user when they have a score that's a multiple of ten. */ private void generateScoreNotification() { int suc = Score.getSuccesses(); int mod = suc % 10; if (suc < 0 || mod != 0) return; String title = "MathApp Score"; String text = "MathApp score reached " + suc + " points!"; Intent onTrigger = new Intent(this, ActivityScore.class); PendingIntent pending = PendingIntent.getActivity(this, 0, onTrigger, Intent.FLAG_ACTIVITY_NEW_TASK); int nResID = R.drawable.ic_launcher; String nText = title; long nTime = System.currentTimeMillis(); Notification notification = new Notification(nResID, nText, nTime); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, title, text, pending); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, notification); }