List of usage examples for android.content Context NOTIFICATION_SERVICE
String NOTIFICATION_SERVICE
To view the source code for android.content Context NOTIFICATION_SERVICE.
Click Source Link
From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java
/** * Called by the Android system in response to a request to run the sync adapter. The work * required to read data from the network, parse it, and store it in the content provider is * done here. Extending AbstractThreadedSyncAdapter ensures that all methods within SyncAdapter * run on a background thread. For this reason, blocking I/O and other long-running tasks can be * run <em>in situ</em>, and you don't have to set up a separate thread for them. . * * <p>This is where we actually perform any work required to perform a sync. * {@link AbstractThreadedSyncAdapter} guarantees that this will be called on a non-UI thread, * so it is safe to peform blocking I/O here. * * <p>The syncResult argument allows you to pass information back to the method that triggered * the sync.//from w ww. j a va 2 s . c om */ @Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.d("SyncAdapter", "onPerformSync"); Log.i(TAG, "Beginning network synchronization"); try { final URL location = new URL(FEED_URL); InputStream stream = null; try { Log.i(TAG, "Streaming data from network: " + location); // stream = downloadUrl(location); // updateLocalFeedData(stream, syncResult); // TODO Auto-generated method stub prefs = mcontext.getSharedPreferences("com.roamprocess1.roaming4world", Context.MODE_PRIVATE); stored_user_mobile_no = "com.roamprocess1.roaming4world.user_mobile_no"; stored_user_country_code = "com.roamprocess1.roaming4world.user_country_code"; stored_user_bal = "com.roamprocess1.roaming4world.user_bal"; stored_min_call_credit = "com.roamprocess1.roaming4world.min_call_credit"; stored_server_ipaddress = "com.roamprocess1.roaming4world.server_ip"; signUpProcess = "com.roamprocess1.roaming4world.signUpProcess"; resultIntent = new Intent(mcontext, SipHome.class); mNotificationManager = (NotificationManager) mcontext .getSystemService(Context.NOTIFICATION_SERVICE); selfNumber = prefs.getString(stored_user_country_code, "") + prefs.getString(stored_user_mobile_no, ""); if (getConnectivityStatus(mcontext) != SipHome.TYPE_NOT_CONNECTED) { updateUserContacts(); updateUserImages(); updateOfflineMissedCalls(); } // Makes sure that the InputStream is closed after the app is // finished using it. } finally { // mcontext.startActivity(new Intent(mcontext , SipHome.class)); if (stream != null) { stream.close(); } } } catch (MalformedURLException e) { Log.wtf(TAG, "Feed URL is malformed", e); syncResult.stats.numParseExceptions++; return; } catch (IOException e) { Log.e(TAG, "Error reading from network: " + e.toString()); syncResult.stats.numIoExceptions++; return; } Log.i(TAG, "Network synchronization complete"); }
From source file:com.ntsync.android.sync.activities.PaymentVerificationService.java
private static void sendNotification(Context context, Account account, int msg, Class<? extends Activity> activityClass, boolean showMsg) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent viewIntent = new Intent(context, activityClass); if (ShopActivity.class.equals(activityClass)) { // Vollstndige Meldung in der View anzeigen CharSequence msgText = context.getText(msg); if (showMsg) { // Show Full Message in ShopActivity viewIntent.putExtra(ShopActivity.PARM_MSG, String .format(context.getText(R.string.shop_activity_delayedverif_failed).toString(), msgText)); }// w w w. j ava2 s .co m viewIntent.putExtra(ShopActivity.PARM_ACCOUNT_NAME, account.name); } // Adds the back stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(activityClass); stackBuilder.addNextIntent(viewIntent); // Photo sync possible. NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(Constants.NOTIF_ICON).setContentTitle(context.getText(msg)) .setContentText(account.name).setAutoCancel(true).setOnlyAlertOnce(true) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); notificationManager.notify(Constants.NOTIF_PAYMENT_VERIFICATIONRESULT, builder.build()); }
From source file:com.granita.icloudcalsync.syncadapter.DavSyncAdapter.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override//from ww w.j a v a2 s.c om public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.i(TAG, "Performing sync for authority " + authority); // set class loader for iCal4j ResourceLoader Thread.currentThread().setContextClassLoader(getContext().getClassLoader()); // create httpClient, if necessary httpClientLock.writeLock().lock(); if (httpClient == null) { Log.d(TAG, "Creating new DavHttpClient"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); httpClient = DavHttpClient.create(); } // prevent httpClient shutdown until we're ready by holding a read lock // acquiring read lock before releasing write lock will downgrade the write lock to a read lock httpClientLock.readLock().lock(); httpClientLock.writeLock().unlock(); // TODO use VCard 4.0 if possible AccountSettings accountSettings = new AccountSettings(getContext(), account); Log.d(TAG, "Server supports VCard version " + accountSettings.getAddressBookVCardVersion()); Exception exceptionToShow = null; // exception to show notification for Intent exceptionIntent = null; // what shall happen when clicking on the exception notification try { // get local <-> remote collection pairs Map<LocalCollection<?>, RemoteCollection<?>> syncCollections = getSyncPairs(account, provider); if (syncCollections == null) Log.i(TAG, "Nothing to synchronize"); else try { for (Map.Entry<LocalCollection<?>, RemoteCollection<?>> entry : syncCollections.entrySet()) new SyncManager(entry.getKey(), entry.getValue()) .synchronize(extras.containsKey(ContentResolver.SYNC_EXTRAS_MANUAL), syncResult); } catch (DavException ex) { syncResult.stats.numParseExceptions++; Log.e(TAG, "Invalid DAV response", ex); exceptionToShow = ex; } catch (HttpException ex) { if (ex.getCode() == HttpStatus.SC_UNAUTHORIZED) { Log.e(TAG, "HTTP Unauthorized " + ex.getCode(), ex); syncResult.stats.numAuthExceptions++; // hard error exceptionToShow = ex; exceptionIntent = new Intent(context, AccountActivity.class); exceptionIntent.putExtra(AccountActivity.EXTRA_ACCOUNT, account); } else if (ex.isClientError()) { Log.e(TAG, "Hard HTTP error " + ex.getCode(), ex); syncResult.stats.numParseExceptions++; // hard error exceptionToShow = ex; } else { Log.w(TAG, "Soft HTTP error " + ex.getCode() + " (Android will try again later)", ex); syncResult.stats.numIoExceptions++; // soft error } } catch (LocalStorageException ex) { syncResult.databaseError = true; // hard error Log.e(TAG, "Local storage (content provider) exception", ex); exceptionToShow = ex; } catch (IOException ex) { syncResult.stats.numIoExceptions++; // soft error Log.e(TAG, "I/O error (Android will try again later)", ex); if (ex instanceof SSLException) // always notify on SSL/TLS errors exceptionToShow = ex; } catch (URISyntaxException ex) { syncResult.stats.numParseExceptions++; // hard error Log.e(TAG, "Invalid URI (file name) syntax", ex); exceptionToShow = ex; } } finally { // allow httpClient shutdown httpClientLock.readLock().unlock(); } // show sync errors as notification if (exceptionToShow != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (exceptionIntent == null) exceptionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.WEB_URL_VIEW_LOGS)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, exceptionIntent, 0); Notification.Builder builder = new Notification.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setPriority(Notification.PRIORITY_LOW).setOnlyAlertOnce(true) .setWhen(System.currentTimeMillis()) .setContentTitle(context.getString(R.string.sync_error_title)) .setContentText(exceptionToShow.getLocalizedMessage()).setContentInfo(account.name) .setStyle(new Notification.BigTextStyle() .bigText(account.name + ":\n" + ExceptionUtils.getFullStackTrace(exceptionToShow))) .setContentIntent(contentIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(account.name.hashCode(), builder.build()); } Log.i(TAG, "Sync complete for " + authority); }
From source file:de.yaacc.upnp.server.YaaccUpnpServerService.java
/** * Cancels the notification.//from w ww .j av a 2 s . c om */ private void cancleNotification() { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.cancel(NotificationId.UPNP_SERVER.getId()); }
From source file:com.vendsy.bartsy.venue.GCMIntentService.java
/** * To generate a notification to inform the user that server has sent a message. * //from ww w. j a va2s . c o m * @param count * @param count */ private static void generateNotification(Context context, String message, String count) { 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; try { int countValue = Integer.parseInt(count); notification.number = countValue; } catch (NumberFormatException e) { e.printStackTrace(); } // // Play default notification sound notification.defaults = Notification.DEFAULT_SOUND; notificationManager.notify(0, notification); }
From source file:com.nextgis.firereporter.GetFiresService.java
protected void Prepare() { mLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mnCurrentExec = 0;// w ww.j a va2 s .c o m mmoFires = new HashMap<Long, FireItem>(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nUserCount = 0; nNasaCount = 0; nScanexCount = 0; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(new Intent(this, MainActivity.class)); //stackBuilder.addNextIntent(new Intent(this, ScanexNotificationsActivity.class)); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_fire_small) .setContentTitle(getString(R.string.stNewFireNotifications)); mBuilder.setContentIntent(resultPendingIntent); Intent delIntent = new Intent(this, GetFiresService.class); delIntent.putExtra(COMMAND, SERVICE_NOTIFY_DISMISSED); PendingIntent deletePendingIntent = PendingIntent.getService(this, 0, delIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setDeleteIntent(deletePendingIntent); mInboxStyle = new NotificationCompat.InboxStyle(); mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes)); LoadScanexData(); mSanextCookieTime = new Time(); mSanextCookieTime.setToNow(); msScanexLoginCookie = new String("not_set"); mFillDataHandler = new Handler() { public void handleMessage(Message msg) { mnCurrentExec--; Bundle resultData = msg.getData(); boolean bHaveErr = resultData.getBoolean(ERROR); if (bHaveErr) { SendError(resultData.getString(ERR_MSG)); } else { int nType = resultData.getInt(SOURCE); String sData = resultData.getString(JSON); switch (nType) { case 3: FillScanexData(nType, sData); break; case 4: msScanexLoginCookie = sData; mSanextCookieTime.setToNow(); GetScanexData(false); break; default: FillData(nType, sData); break; } } GetDataStoped(); }; }; }
From source file:com.raspi.chatapp.util.Notification.java
public void reset() { SharedPreferences preferences = context.getSharedPreferences(Constants.PREFERENCES, 0); preferences.edit().putString(NOTIFICATION_OLD_BUDDY, "").putString(CURRENT_NOTIFICATIONS, "").apply(); ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(Notification.NOTIFICATION_ID); }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void notifyMatch(long matchId) { if (!PrefUtils.shouldShowMatchReminders(this)) { return;//from w w w .ja va2s.c om } final ContentResolver cr = getContentResolver(); Cursor c = cr.query(MatchContract.SeriesEntry.CONTENT_URI, MatchDetailQuery.PROJECTION, SESSION_ID_WHERE_CLAUSE, new String[] { String.valueOf(matchId) }, null); if (!c.moveToNext()) { return; } Intent baseIntent = new Intent(this, MatchActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); Intent matchIntent = new Intent(this, MatchDetailActivity.class); matchIntent.putExtra(MatchDetailActivity.ARGS_GG_MATCH_ID, matchId); taskBuilder.addNextIntent(matchIntent); PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentTitle = c.getString(MatchDetailQuery.TEAM_ONE_NAME) + " vs " + c.getString(MatchDetailQuery.TEAM_TWO_NAME); String contentText; long currentTime = TimeUtils.getUTCTime(); long matchStart = c.getLong(MatchDetailQuery.DATE_TIME); int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000; if (minutesLeft < 2 && minutesLeft >= 0) { minutesLeft = 1; } if (minutesLeft < 0) { contentText = "is scheduled to start now. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } else { contentText = "is scheduled to start in " + minutesLeft + " min. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle) .setContentText(contentText).setColor(res.getColor(R.color.theme_primary)) .setTicker(contentTitle + " is about to start.") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_DEFAULT).setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notifBuilder.build()); }
From source file:at.flack.receiver.SmsReceiver.java
@Override public void onReceive(Context context, Intent intent) { sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); notify = sharedPrefs.getBoolean("notifications", true); vibrate = sharedPrefs.getBoolean("vibration", true); headsup = sharedPrefs.getBoolean("headsup", true); led_color = sharedPrefs.getInt("notification_light", -16776961); boolean all = sharedPrefs.getBoolean("all_sms", true); if (notify == false) return;//from w ww . j av a 2s . com Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += msgs[i].getMessageBody().toString(); str += "\n"; } NotificationCompat.Builder mBuilder; if (main != null) { main.addNewMessage(str); return; } boolean use_profile_picture = false; Bitmap profile_picture = null; String origin_name = null; try { origin_name = getContactName(context, msgs[0].getDisplayOriginatingAddress()); if (origin_name == null) origin_name = msgs[0].getDisplayOriginatingAddress(); } catch (Exception e) { } if (origin_name == null) origin_name = "Unknown"; try { profile_picture = RoundedImageView.getCroppedBitmap(Bitmap.createScaledBitmap( fetchThumbnail(context, msgs[0].getDisplayOriginatingAddress()), 200, 200, false), 300); use_profile_picture = true; } catch (Exception e) { use_profile_picture = false; } Resources res = context.getResources(); int positionOfBase64End = str.lastIndexOf("="); if (positionOfBase64End > 0 && Base64.isBase64(str.substring(0, positionOfBase64End))) { mBuilder = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.raven_notification_icon) .setContentTitle(origin_name).setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_new_encrypted)).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else if (str.toString().charAt(0) == '%' && (str.toString().length() == 10 || str.toString().length() == 9)) { int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else if (str.toString().charAt(0) == '%' && str.toString().length() >= 120 && str.toString().length() < 125) { // DH Handshake int lastIndex = str.toString().lastIndexOf("="); if (lastIndex > 0 && Base64.isBase64(str.toString().substring(1, lastIndex))) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C) .setContentText(res.getString(R.string.sms_receiver_handshake_received)) .setSmallIcon(R.drawable.raven_notification_icon).setAutoCancel(true); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } else { // unencrypted messages if (all) { mBuilder = new NotificationCompat.Builder(context).setContentTitle(origin_name) .setColor(0xFFB71C1C).setContentText(str).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(str)) .setSmallIcon(R.drawable.raven_notification_icon); if (use_profile_picture && profile_picture != null) { mBuilder = mBuilder.setLargeIcon(profile_picture); } else { mBuilder = mBuilder.setLargeIcon(convertToBitmap(origin_name, context.getResources().getDrawable(R.drawable.ic_social_person), 200, 200)); } } else { return; } } Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); mBuilder.setLights(led_color, 750, 4000); if (vibrate) { mBuilder.setVibrate(new long[] { 0, 100, 200, 300 }); } Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); resultIntent.putExtra("CONTACT_NUMBER", msgs[0].getOriginatingAddress()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (Build.VERSION.SDK_INT >= 16 && headsup) mBuilder.setPriority(Notification.PRIORITY_HIGH); if (Build.VERSION.SDK_INT >= 21) mBuilder.setCategory(Notification.CATEGORY_MESSAGE); final NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && !MainActivity.isOnTop) mNotificationManager.notify(7, mBuilder.build()); // Save SMS if default app if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && Telephony.Sms.getDefaultSmsPackage(context).equals(context.getPackageName())) { ContentValues values = new ContentValues(); values.put("address", msgs[0].getDisplayOriginatingAddress()); values.put("body", str.replace("\n", "").replace("\r", "")); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) context.getContentResolver().insert(Telephony.Sms.Inbox.CONTENT_URI, values); } } }
From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java
@Override protected void onResume() { super.onResume(); ActivityMonitor.getInstance().setCurrentActivity(this); Integer id = Notifications.getInstance(getApplicationContext()).getNotificationIds().get(contact); if (id != null) { NotificationManager notificationManager = (NotificationManager) getApplicationContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(id);/*from ww w. j av a 2s.co m*/ } markConversationAsRead(); adapter.refresh(); }