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.piusvelte.sonet.core.PhotoUploadService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); if (Sonet.ACTION_UPLOAD.equals(action)) { if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE) && intent.hasExtra(Widgets.INSTANT_UPLOAD)) { String place = null; if (intent.hasExtra(Splace)) place = intent.getStringExtra(Splace); String tags = null; if (intent.hasExtra(Stags)) tags = intent.getStringExtra(Stags); // upload a photo Notification notification = new Notification(R.drawable.notification, "uploading photo", System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading", PendingIntent.getActivity(PhotoUploadService.this, 0, (Sonet.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification);/*from ww w. j a va2 s. c o m*/ (new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String response = null; if (params.length > 2) { Log.d(TAG, "upload file: " + params[2]); HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL, Saccess_token, mSonetCrypto.Decrypt(params[0]))); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file = new File(params[2]); ContentBody fileBody = new FileBody(file); entity.addPart(Ssource, fileBody); HttpClient httpClient = SonetHttpClient .getThreadSafeClient(getApplicationContext()); try { entity.addPart(Smessage, new StringBody(params[1])); if (params[3] != null) entity.addPart(Splace, new StringBody(params[3])); if (params[4] != null) entity.addPart(Stags, new StringBody(params[4])); httpPost.setEntity(entity); response = SonetHttpClient.httpResponse(httpClient, httpPost); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } } return response; } @Override protected void onPostExecute(String response) { // notify photo success String message = getString(response != null ? R.string.success : R.string.failure); Notification notification = new Notification(R.drawable.notification, "photo upload " + message, System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", message, PendingIntent.getActivity(PhotoUploadService.this, 0, (Sonet.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification); stopSelfResult(mStartId); } }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE), intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags); } } } }
From source file:com.android.settings.aokpstats.ReportingService.java
private void promptUser() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent nI = new Intent(); nI.setComponent(new ComponentName(getPackageName(), Settings.AnonymousStatsActivity.class.getName())); PendingIntent pI = PendingIntent.getActivity(this, 0, nI, 0); Notification.Builder builder = new Notification.Builder(this).setSmallIcon(R.drawable.ic_aokp_stats_notif) .setAutoCancel(true).setTicker(getString(R.string.anonymous_statistics_title)).setContentIntent(pI) .setWhen(0).setContentTitle(getString(R.string.anonymous_statistics_title)) .setContentText(getString(R.string.anonymous_notification_desc)); nm.notify(1, builder.getNotification()); }
From source file:com.shafiq.myfeedle.core.PhotoUploadService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); if (Myfeedle.ACTION_UPLOAD.equals(action)) { if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE) && intent.hasExtra(Widgets.INSTANT_UPLOAD)) { String place = null; if (intent.hasExtra(Splace)) place = intent.getStringExtra(Splace); String tags = null; if (intent.hasExtra(Stags)) tags = intent.getStringExtra(Stags); // upload a photo Notification notification = new Notification(R.drawable.notification, "uploading photo", System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading", PendingIntent.getActivity(PhotoUploadService.this, 0, (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification);// w w w . j a v a 2s . com (new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String response = null; if (params.length > 2) { Log.d(TAG, "upload file: " + params[2]); HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL, Saccess_token, mMyfeedleCrypto.Decrypt(params[0]))); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file = new File(params[2]); ContentBody fileBody = new FileBody(file); entity.addPart(Ssource, fileBody); HttpClient httpClient = MyfeedleHttpClient .getThreadSafeClient(getApplicationContext()); try { entity.addPart(Smessage, new StringBody(params[1])); if (params[3] != null) entity.addPart(Splace, new StringBody(params[3])); if (params[4] != null) entity.addPart(Stags, new StringBody(params[4])); httpPost.setEntity(entity); response = MyfeedleHttpClient.httpResponse(httpClient, httpPost); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } } return response; } @Override protected void onPostExecute(String response) { // notify photo success String message = getString(response != null ? R.string.success : R.string.failure); Notification notification = new Notification(R.drawable.notification, "photo upload " + message, System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", message, PendingIntent.getActivity(PhotoUploadService.this, 0, (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification); stopSelfResult(mStartId); } }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE), intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags); } } } }
From source file:com.rocketsingh.biker.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w. j a v a 2 s .c om*/ public 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, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // 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, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:cw.kop.autobackground.files.DownloadThread.java
@Override public void run() { super.run();/* www . ja v a 2 s .c o m*/ Looper.prepare(); if (AppSettings.useDownloadNotification()) { PendingIntent pendingStopIntent = PendingIntent.getBroadcast(appContext, 0, new Intent(LiveWallpaperService.STOP_DOWNLOAD), 0); notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); notifyProgress = new Notification.Builder(appContext).setContentTitle("AutoBackground") .setContentText("Downloading images...").setSmallIcon(R.drawable.ic_photo_white_24dp); if (Build.VERSION.SDK_INT >= 16) { notifyProgress.setPriority(Notification.PRIORITY_MIN); notifyProgress.addAction(R.drawable.ic_cancel_white_24dp, "Stop Download", pendingStopIntent); } updateNotification(0); } String downloadCacheDir = AppSettings.getDownloadPath(); File cache = new File(downloadCacheDir); if (!cache.exists() || !cache.isDirectory()) { cache.mkdir(); } List<Integer> indexes = new ArrayList<>(); for (int index = 0; index < AppSettings.getNumberSources(); index++) { Source source = AppSettings.getSource(index); if (!source.getType().equals(AppSettings.FOLDER) && source.isUse()) { indexes.add(index); progressMax += source.getNum(); } } usedLinks = new HashSet<>(); if (AppSettings.checkDuplicates()) { Set<String> rawLinks = AppSettings.getUsedLinks(); for (String link : rawLinks) { if (link.lastIndexOf("Time:") > 0) { link = link.substring(0, link.lastIndexOf("Time:")); } usedLinks.add(link); } } downloadedFiles = new ArrayList<>(); for (int index : indexes) { Source source = AppSettings.getSource(index); if (isInterrupted()) { cancel(); return; } try { if (AppSettings.deleteOldImages()) { FileHandler.deleteBitmaps(appContext, source); } String title = source.getTitle(); File file = new File(downloadCacheDir + "/" + title + " " + AppSettings.getImagePrefix()); if (!file.exists() || !file.isDirectory()) { file.mkdir(); } String sourceType = source.getType(); String sourceData = source.getData(); switch (sourceType) { case AppSettings.WEBSITE: downloadWebsite(sourceData, source); break; case AppSettings.IMGUR_SUBREDDIT: downloadImgurSubreddit(sourceData, source); break; case AppSettings.IMGUR_ALBUM: downloadImgurAlbum(sourceData, source); break; case AppSettings.GOOGLE_ALBUM: downloadPicasa(sourceData, source); break; case AppSettings.TUMBLR_BLOG: downloadTumblrBlog(sourceData, source); break; case AppSettings.TUMBLR_TAG: downloadTumblrTag(sourceData, source); break; case AppSettings.REDDIT_SUBREDDIT: downloadRedditSubreddit(sourceData, source); break; } totalTarget += source.getNum(); updateNotification(totalTarget); } catch (IOException | IllegalArgumentException e) { sendToast("Invalid URL: " + source.getData()); Log.i(TAG, "Invalid URL"); } } finish(); }
From source file:br.com.recidev.gamethis.util.GcmIntentService.java
private void sendNotification(String msg, String tipoNotificacao, Bundle extras) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = null;/*from w w w. j ava 2s . com*/ if (tipoNotificacao.equals("Novo Usuario")) { Usuario usuario = new Usuario(); usuario.setNome(extras.getString("nome")); usuario.setEmail(extras.getString("email")); usuario.setSenha(extras.getString("senha")); usuario.setAvatar(Integer.parseInt(extras.getString("avatar"))); usuario.setNome(extras.getString("syncStatus")); usuario.setGcm_id(extras.getString("gcm_id")); contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0); } if (tipoNotificacao.equals("Novo Jogo")) { //TODO Ajustar depois o encaminhamento para meus jogos contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, HomeActivity.class), 0); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.game_this_2).setContentTitle("GameThis") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.toasty); mBuilder.setSound(sound); int defaults = 0; defaults = defaults | Notification.DEFAULT_LIGHTS; defaults = defaults | Notification.DEFAULT_VIBRATE; //defaults = defaults | Notification.DEFAULT_SOUND; mBuilder.setDefaults(defaults); mBuilder.setAutoCancel(true); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:ar.fi.uba.jobify.service.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w ww . j a v a2 s . c om*/ private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) //.setSmallIcon(R.drawable.ic_stat_ic_notification) .setContentTitle("FCM Message").setContentText(messageBody).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.google.android.gcm.demo.app.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from www .j a v a 2 s . com private static void generateNotification(Context context, String message, String data) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, DemoActivity.class); notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data); // 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, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.pushnotificationsapp.app.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, DemoActivity.class), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:json2notification.MainTest.java
@Before public void setup() { MockitoAnnotations.initMocks(this); supportFragment = new android.support.v4.app.Fragment(); fragmentActivity = Robolectric.buildActivity(FragmentActivity.class).create().get(); fragmentActivity.getSupportFragmentManager().beginTransaction().add(supportFragment, null).commit(); fragment = new Fragment(); activity = Robolectric.buildActivity(Activity.class).create().get(); activity.getFragmentManager().beginTransaction().add(fragment, null).commit(); NotificationManager notificationManager = (NotificationManager) Robolectric.application .getSystemService(Context.NOTIFICATION_SERVICE); }