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:br.org.projeto.vigilante.push.MyGcmListenerService.java
private void sendNotification(String message) { Intent intent = MainActivity_.intent(this).get(); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.drawable.ic_stat_action_account_child) .setColor(getResources().getColor(R.color.colorPrimary)) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java
@Override /**//from w w w.j a v a 2 s . co m * starts the service and gets ready to send bookmark * * this service is supposed to only get started once for every bookmark * so if onStart is called it means a new bookmark needs to be sent */ public void onStart(Intent intent, int startId) { super.onStart(intent, startId); // init notification manager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (intent.hasExtra(Global.EXTRA_TITLE) && intent.hasExtra(Global.EXTRA_URL)) { title = intent.getStringExtra(Global.EXTRA_TITLE); url = intent.getStringExtra(Global.EXTRA_URL); Log.d(Global.TAG, "started BackgroundSharingService with values " + title + " " + url); sendToServer(title, url); } else { // if we're not called with a title and url, stop the service stopSelf(); return; } }
From source file:androidx.navigation.testapp.AndroidFragment.java
@Override public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); TextView tv = view.findViewById(R.id.text); tv.setText(getArguments().getString("myarg")); Button b = view.findViewById(R.id.send_notification); b.setOnClickListener(new View.OnClickListener() { @Override//w w w . j a va2 s .co m public void onClick(View v) { EditText editArgs = view.findViewById(R.id.edit_args); Bundle args = new Bundle(); args.putString("myarg", editArgs.getText().toString()); PendingIntent deeplink = Navigation.findNavController(v).createDeepLink() .setDestination(R.id.android).setArguments(args).createPendingIntent(); NotificationManager notificationManager = (NotificationManager) requireContext() .getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationManager.createNotificationChannel( new NotificationChannel("deeplink", "Deep Links", NotificationManager.IMPORTANCE_HIGH)); } NotificationCompat.Builder builder = new NotificationCompat.Builder(requireContext(), "deeplink") .setContentTitle("Navigation").setContentText("Deep link to Android") .setSmallIcon(R.drawable.ic_android).setContentIntent(deeplink).setAutoCancel(true); notificationManager.notify(0, builder.build()); } }); }
From source file:luan.com.flippit.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { mContext = this; mPrefs = getSharedPreferences(mContext.getPackageName(), Context.MODE_PRIVATE); mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); mBuilder = new NotificationCompat.Builder(this); activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); Bundle extras = intent.getExtras();/*from w w w .j a va2s.c o m*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); String message = intent.getStringExtra("message"); String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { manageNotification(message); } } GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.flowzr.budget.holo.export.flowzr.FlowzrBillTask.java
protected Object work(Context context, DatabaseAdapter dba, String... params) throws ImportExportException { AccountManager accountManager = AccountManager.get(context); android.accounts.Account[] accounts = accountManager.getAccountsByType("com.google"); String accountName = MyPreferences.getFlowzrAccount(context); if (accountName == null) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, FlowzrSyncActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Builder mNotifyBuilder = new NotificationCompat.Builder(context); mNotifyBuilder.setContentIntent(contentIntent).setSmallIcon(R.drawable.icon) .setWhen(System.currentTimeMillis()).setAutoCancel(true) .setContentTitle(context.getString(R.string.flowzr_sync)) .setContentText(context.getString(R.string.flowzr_choose_account)); nm.notify(0, mNotifyBuilder.build()); Log.i("Flowzr", "account name is null"); throw new ImportExportException(R.string.flowzr_choose_account); }//ww w .j a va 2s.c o m Account useCredential = null; for (int i = 0; i < accounts.length; i++) { if (accountName.equals(((android.accounts.Account) accounts[i]).name)) { useCredential = accounts[i]; } } AccountManager.get(context).getAuthToken(useCredential, "ah", null, (Activity) context, new GetAuthTokenCallback(), null); return null; }
From source file:com.sir_m2x.messenger.utils.CustomExceptionHandler.java
@Override public void uncaughtException(final Thread t, final Throwable e) { ((NotificationManager) this.context.getSystemService(Context.NOTIFICATION_SERVICE)).cancelAll(); Utils.saveEventLog(MessengerService.getEventLog()); SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HHMM"); String timestamp = df.format(new Date(System.currentTimeMillis())); final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter);//from ww w . j a v a2 s .c om String stacktrace = result.toString(); printWriter.close(); String filename = timestamp + " " + Build.VERSION.SDK_INT + ".stacktrace"; if (Preferences.logCrash) // if (this.url != null) // sendToServer(stacktrace, filename); if (this.localPath != null) writeToFile(stacktrace, filename); this.defaultUEH.uncaughtException(t, e); }
From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java
public static void dismissMsgNotification(Context ctx) { final NotificationManager mgr; mgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); mgr.cancel(R.id.activity_main_receive_msg); }
From source file:com.pwned.steamfriends.views.TwitterStream.java
@Override public void onCreate(Bundle savedInstanceState) { setMyTheme();//w w w. jav a 2 s . c o m super.onCreate(savedInstanceState); tracker = GoogleAnalyticsTracker.getInstance(); tracker.start(Constants.UACODE, 20, this); tracker.trackPageView("/TwitterStream"); mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mManager.cancel(APP_ID); setContentView(R.layout.twitter); m_streams = new ArrayList<Stream>(); this.m_adapter = new TwitterStreamAdapter(this, R.layout.row, m_streams); setListAdapter(this.m_adapter); viewStream = new Thread() { @Override public void run() { getStream(); } }; Animation a = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); a.setRepeatMode(Animation.RESTART); a.setRepeatCount(Animation.INFINITE); a.setDuration(750); a.setInterpolator(AnimationUtils.loadInterpolator(this, android.R.anim.linear_interpolator)); ivLoad = (ImageView) findViewById(R.id.loading_spinner); ivLoad.startAnimation(a); Thread thread = new Thread(null, viewStream, "SpecialsBackground"); thread.start(); //m_ProgressDialog = ProgressDialog.show(TwitterStream.this,"","Loading Twitter Stream...", true); steamHeader = (ImageView) findViewById(R.id.headerimage); steamHeader.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.HEADER_URL)); startActivity(myIntent); } }); }
From source file:de.kollode.redminebrowser.sync.SyncHelper.java
void performSync(SyncResult syncResult, Account account) throws IOException { NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); mBuilder.setContentTitle("Projects").setContentText("Syncing in progress") .setSmallIcon(R.drawable.ic_launcher); final ContentResolver resolver = mContext.getContentResolver(); ArrayList<ContentProviderOperation> batch = new ArrayList<ContentProviderOperation>(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); AccountManager accMgr = AccountManager.get(this.mContext); String serverUrl = accMgr.getUserData(account, "serverUrl"); if (isOnline()) { final long startRemote = System.currentTimeMillis(); int syncedProjects = 0; Log.i(sTag, "Remote syncing speakers"); Log.i(sTag, serverUrl);//from w w w. java2 s . com try { int offset = 0; int numberOfProjects; int limit = 100; boolean loadMore = true; do { String restQuery = "sort=updated_on:desc&limit=" + limit + "&offset=" + offset + "&key=" + accMgr.getPassword(account); Log.d(sTag, "REST URL: " + serverUrl + "/projects.json?" + restQuery); JSONObject projectsJson = getJsonFromUrl(serverUrl + "/projects.json?" + restQuery); numberOfProjects = projectsJson.getInt("total_count"); mBuilder.setProgress(numberOfProjects, syncedProjects, false); mNotificationManager.notify(0, mBuilder.build()); if (numberOfProjects < limit + offset) { Log.d(sTag, "Enough Projects"); loadMore = false; } else { Log.d(sTag, "More Projects"); offset += limit; } JSONArray projects = projectsJson.getJSONArray("projects"); for (int i = 0; i < projects.length(); i++) { JSONObject project = projects.getJSONObject(i); Builder projectBuilder = ContentProviderOperation .newInsert(Project.buildProjectsUri(account.name)); Log.d(sTag, project.toString()); try { projectBuilder.withValue(Project.PARENT, project.getJSONObject("parent").getInt("id")); } catch (Exception e) { } batch.add(projectBuilder.withValue(BaseColumns._ID, project.getInt("id")) .withValue(Project.NAME, project.getString("name")) .withValue(Project.IDENTIFIER, project.getString("identifier")) .withValue(Project.UPDATED, System.currentTimeMillis()) .withValue(Project.CREATED, System.currentTimeMillis()) .withValue(Project.CREATED_ON, project.getString("created_on")) .withValue(Project.UPDATED_ON, project.getString("updated_on")).build()); mBuilder.setProgress(numberOfProjects, syncedProjects++, false); mNotificationManager.notify(0, mBuilder.build()); } } while (loadMore && !this.isCanceled()); try { // Apply all queued up batch operations for local data. resolver.applyBatch(RedmineTables.CONTENT_AUTHORITY, batch); } catch (RemoteException e) { throw new RuntimeException("Problem applying batch operation", e); } catch (OperationApplicationException e) { throw new RuntimeException("Problem applying batch operation", e); } } catch (Exception e) { e.printStackTrace(); } if (this.isCanceled()) { mBuilder.setContentText("Sync was canceled").setProgress(0, 0, false); } else { mBuilder.setContentText("Sync complete").setProgress(0, 0, false); } mNotificationManager.notify(0, mBuilder.build()); syncResult.delayUntil = ((long) 60 * 60); Log.d(sTag, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); Log.d(sTag, "Number of projects: " + syncedProjects); } }
From source file:biz.atelecom.communicator.MyGcmListenerService.java
private void sendNotification(Bundle data) { //Intent intent = new Intent(this, ChatActivity.class); Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtras(data);//from w ww .j av a2s .com PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.atelecom_ic_notification).setContentTitle("Atelecom Message") .setContentText("message").setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }