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.example.wojtekswiderski.woahpaper.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.wp_logo) .setContentTitle("WoahPaper").setStyle(new NotificationCompat.BigTextStyle().bigText(msg)) .setContentText(msg);/*from w w w . j a va2s. c o m*/ mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.layer.atlas.messenger.AtlasMessagesScreen.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.uiHandler = new Handler(); this.app = (MessengerApp) getApplication(); setContentView(R.layout.atlas_screen_messages); boolean convIsNew = getIntent().getBooleanExtra(EXTRA_CONVERSATION_IS_NEW, false); String convUri = getIntent().getStringExtra(EXTRA_CONVERSATION_URI); if (convUri != null) { Uri uri = Uri.parse(convUri);// w w w .jav a 2 s . co m conv = app.getLayerClient().getConversation(uri); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(convUri.hashCode()); // Clear notifications for this Conversation } participantsPicker = (AtlasParticipantPicker) findViewById(R.id.atlas_screen_messages_participants_picker); participantsPicker.init(new String[] { app.getLayerClient().getAuthenticatedUserId() }, app.getParticipantProvider()); if (convIsNew) { participantsPicker.setVisibility(View.VISIBLE); } messageComposer = (AtlasMessageComposer) findViewById(R.id.atlas_screen_messages_message_composer); messageComposer.init(app.getLayerClient(), conv); messageComposer.setListener(new AtlasMessageComposer.Listener() { public boolean beforeSend(Message message) { boolean conversationReady = ensureConversationReady(); if (!conversationReady) return false; // push preparePushMetadata(message); return true; } }); messageComposer.registerMenuItem("Photo", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); String fileName = "cameraOutput" + System.currentTimeMillis() + ".jpg"; photoFile = new File(getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES), fileName); final Uri outputUri = Uri.fromFile(photoFile); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri); if (debug) Log.w(TAG, "onClick() requesting photo to file: " + fileName + ", uri: " + outputUri); startActivityForResult(cameraIntent, REQUEST_CODE_CAMERA); } }); messageComposer.registerMenuItem("Image", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; // in onCreate or any event where your want the user to select a file Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), REQUEST_CODE_GALLERY); } }); messageComposer.registerMenuItem("Location", new OnClickListener() { public void onClick(View v) { if (!ensureConversationReady()) return; if (lastKnownLocation == null) { Toast.makeText(v.getContext(), "Inserting Location: Location is unknown yet", Toast.LENGTH_SHORT).show(); return; } String locationString = "{\"lat\":" + lastKnownLocation.getLatitude() + ", \"lon\":" + lastKnownLocation.getLongitude() + "}"; MessagePart part = app.getLayerClient().newMessagePart(Atlas.MIME_TYPE_ATLAS_LOCATION, locationString.getBytes()); Message message = app.getLayerClient().newMessage(Arrays.asList(part)); preparePushMetadata(message); conv.send(message); if (debug) Log.w(TAG, "onSendLocation() loc: " + locationString); } }); messagesList = (AtlasMessagesList) findViewById(R.id.atlas_screen_messages_messages_list); messagesList.init(app.getLayerClient(), app.getParticipantProvider()); if (USE_QUERY) { Query<Message> query = Query.builder(Message.class) .predicate(new Predicate(Message.Property.CONVERSATION, Predicate.Operator.EQUAL_TO, conv)) .sortDescriptor(new SortDescriptor(Message.Property.POSITION, SortDescriptor.Order.ASCENDING)) .build(); messagesList.setQuery(query); } else { messagesList.setConversation(conv); } messagesList.setItemClickListener(new ItemClickListener() { public void onItemClick(Cell cell) { if (Atlas.MIME_TYPE_ATLAS_LOCATION.equals(cell.messagePart.getMimeType())) { String jsonLonLat = new String(cell.messagePart.getData()); JSONObject json; try { json = new JSONObject(jsonLonLat); double lon = json.getDouble("lon"); double lat = json.getDouble("lat"); Intent openMapIntent = new Intent(Intent.ACTION_VIEW); String uriString = String.format(Locale.ENGLISH, "geo:%f,%f?z=%d&q=%f,%f", lat, lon, 18, lat, lon); final Uri geoUri = Uri.parse(uriString); openMapIntent.setData(geoUri); if (openMapIntent.resolveActivity(getPackageManager()) != null) { startActivity(openMapIntent); if (debug) Log.w(TAG, "onItemClick() starting Map: " + uriString); } else { if (debug) Log.w(TAG, "onItemClick() No Activity to start Map: " + geoUri); } } catch (JSONException ignored) { } } else if (cell instanceof ImageCell) { Intent intent = new Intent(AtlasMessagesScreen.this.getApplicationContext(), AtlasImageViewScreen.class); app.setParam(intent, cell); startActivity(intent); } } }); typingIndicator = (AtlasTypingIndicator) findViewById(R.id.atlas_screen_messages_typing_indicator); typingIndicator.init(conv, new AtlasTypingIndicator.DefaultTypingIndicatorCallback(app.getParticipantProvider())); // location manager for inserting locations: this.locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); prepareActionBar(); }
From source file:com.googlecode.android_scripting.facade.AndroidFacade.java
public AndroidFacade(FacadeManager manager) { super(manager); mService = manager.getService();/*from www . j a v a2s .c om*/ mIntent = manager.getIntent(); BaseApplication application = ((BaseApplication) mService.getApplication()); mTaskQueue = application.getTaskExecutor(); mHandler = new Handler(mService.getMainLooper()); mVibrator = (Vibrator) mService.getSystemService(Context.VIBRATOR_SERVICE); mNotificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); mResources = manager.getAndroidFacadeResources(); }
From source file:com.gdglab.iot.gcm.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, GdglabActivity.class); resultIntent.putExtra("msgText", msg); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); //Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(GdglabActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 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(resultPendingIntent); Notification note = mBuilder.build(); note.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, note); }
From source file:com.carpool.dj.carpool.model.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//* w w w . j av a2 s . c o m*/ @SuppressWarnings("deprecation") private static void generateNotification(Context context, String message, Bundle data, String type) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Notification notification = new Notification(icon, message, when); Notification notification = new Notification.Builder(context) .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message) .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build(); // String title = context.getString(R.string.app_name); Intent notificationIntent = null; if ("CarEvent".equals(type)) { notificationIntent = new Intent(context, ContentActivity.class); } else { return; } notificationIntent.putExtras(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, Utils.nowActivity.getString(R.string.app_name), message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.pwned.steamfriends.views.TwitterStream.java
@Override protected void onResume() { setMyTheme();/* w w w . ja v a 2s .c o m*/ super.onResume(); mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mManager.cancel(APP_ID); }
From source file:com.keithandthegirl.services.download.DownloadService.java
@TargetApi(8) @Override// w w w .j a v a 2 s. c om protected void onHandleIntent(Intent requestIntent) { Log.v(TAG, "onHandleIntent : enter"); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mOriginalRequestIntent = requestIntent; Resource resourceType = Resource.valueOf(requestIntent.getStringExtra(RESOURCE_TYPE_EXTRA)); mCallback = requestIntent.getParcelableExtra(SERVICE_CALLBACK); Uri data = requestIntent.getData(); String urlPath = requestIntent.getStringExtra("urlpath"); String directory = requestIntent.getStringExtra("directory"); String filename = data.getLastPathSegment(); File root; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { switch (resourceType) { case MP3: root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS); break; case MP4: root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); break; case M4V: root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES); break; case JPG: root = getExternalCacheDir(); filename = requestIntent.getLongExtra("id", -1) + ".jpg"; break; default: root = getExternalCacheDir(); break; } } else { root = Environment.getExternalStorageDirectory(); } File outputDir = new File(root, directory); outputDir.mkdirs(); File output = new File(outputDir, filename); if (output.exists()) { result = FragmentActivity.RESULT_OK; mCallback.send(result, getOriginalIntentBundle()); Log.v(TAG, "onHandleIntent : exit, image exists"); return; } switch (resourceType) { case MP3: Log.v(TAG, "onHandleIntent : saving mp3"); savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; case MP4: Log.v(TAG, "onHandleIntent : saving mp4"); savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; case M4V: Log.v(TAG, "onHandleIntent : saving m4v"); savePodcast(requestIntent.getLongExtra("id", -1), requestIntent.getStringExtra("title"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; case JPG: Log.v(TAG, "onHandleIntent : saving jpg"); saveBitmap(requestIntent.getStringExtra("filename"), urlPath, output); mCallback.send(result, getOriginalIntentBundle()); break; default: Log.w(TAG, "onHandleIntent : unknown extension '" + resourceType.getExtension() + "'"); mCallback.send(REQUEST_INVALID, getOriginalIntentBundle()); break; } Log.v(TAG, "onHandleIntent : exit"); }
From source file:com.NotifyMe.GcmIntentService.java
private void sendNotificationWithExtras(Bundle extras) { String message = extras.getString("message"); String service = extras.getString("service"); String type = extras.getString("type"); String title = "NotifyMe [" + service + "]"; mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent;//from w w w.jav a2 s .com if (service.equals("Reddit")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = "http://reddit.com"; if (type.equals("reddit-front-page")) { if (Integer.parseInt(extras.getString("count")) == 1) { try { JSONArray posts = new JSONArray(extras.getString("links")); url = posts.getJSONObject(0).getString("url"); message = posts.getJSONObject(0).getString("title"); } catch (JSONException e) { url = "http://reddit.com"; } } else { url = "http://reddit.com"; } } else if (type.equals("user-comment") || type.equals("user-submission")) { url = extras.getString("link"); } resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("weather")) { Intent resultIntent; Intent weatherIntent = getWeatherAppIntent(); if (weatherIntent != null) { resultIntent = weatherIntent; } else { resultIntent = new Intent(Intent.ACTION_VIEW); String url = "http://weather.com/"; resultIntent.setData(Uri.parse(url)); } contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("poly")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = "https://www4.polymtl.ca/poly/poly.html"; resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else if (service.equals("github")) { Intent resultIntent = new Intent(Intent.ACTION_VIEW); String url = extras.getString("link"); resultIntent.setData(Uri.parse(url)); contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); } else { contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(title).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setDefaults(Notification.DEFAULT_VIBRATE).setOnlyAlertOnce(true); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:bucci.dev.freestyle.TimerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_timer); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); settings = getSharedPreferences(SHARED_PREFS_PARAM, MODE_PRIVATE); if (isFirstTimeUsed()) createFirstTimeUsedDialog();//from ww w. ja va 2s. c o m initButtons(); initTimer(); setLastUsedSong(); manageRecreatingActivity(savedInstanceState); }
From source file:app.androidhive.info.realm.GCM.GcmIntentService.java
private void sendNotification(String title, String msg, String link) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); /* Intent intent = new Intent(this, MainActivity.class); intent.putExtra("phone", link);//from ww w. j av a 2 s.com PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);*/ Phone = link; // getData(link); Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class); dialogIntent.putExtra("Phone", link); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setLargeIcon(BitmapFactory.decodeResource(getBaseContext().getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(link).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); // Set the notification vibrate option if (preferences.getBoolean("notifications_new_message_vibrate", true)) { mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }); } // Set the notification ringtone if (preferences.getString("notifications_new_message_ringtone", null) != null) { mBuilder.setSound(Uri.parse(preferences.getString("notifications_new_message_ringtone", null))); } else { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); } // Show only if the notification are enabled if (preferences.getBoolean("notifications_new_message", true)) { // mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); } }