Example usage for android.app NotificationManager from

List of usage examples for android.app NotificationManager from

Introduction

In this page you can find the example usage for android.app NotificationManager from.

Prototype

@UnsupportedAppUsage
public static NotificationManager from(Context context) 

Source Link

Usage

From source file:com.android.shell.BugreportReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    final File bugreportFile = getFileExtra(intent, EXTRA_BUGREPORT);
    final File screenshotFile = getFileExtra(intent, EXTRA_SCREENSHOT);

    // Files are kept on private storage, so turn into Uris that we can
    // grant temporary permissions for.
    final Uri bugreportUri = FileProvider.getUriForFile(context, AUTHORITY, bugreportFile);
    final Uri screenshotUri = FileProvider.getUriForFile(context, AUTHORITY, screenshotFile);

    Intent sendIntent = buildSendIntent(context, bugreportUri, screenshotUri);
    Intent notifIntent;/*w  w w  .j  a v a2s  . co  m*/

    // Send through warning dialog by default
    if (getWarningState(context, STATE_SHOW) == STATE_SHOW) {
        notifIntent = buildWarningIntent(context, sendIntent);
    } else {
        notifIntent = sendIntent;
    }
    notifIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    final Notification.Builder builder = new Notification.Builder(context);
    builder.setSmallIcon(com.android.internal.R.drawable.stat_sys_adb);
    builder.setContentTitle(context.getString(R.string.bugreport_finished_title));
    builder.setTicker(context.getString(R.string.bugreport_finished_title));
    builder.setContentText(context.getString(R.string.bugreport_finished_text));
    builder.setContentIntent(
            PendingIntent.getActivity(context, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT));
    builder.setAutoCancel(true);
    NotificationManager.from(context).notify(TAG, 0, builder.build());

    // Clean up older bugreports in background
    final PendingResult result = goAsync();
    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            FileUtils.deleteOlderFiles(bugreportFile.getParentFile(), MIN_KEEP_COUNT, MIN_KEEP_AGE);
            result.finish();
            return null;
        }
    }.execute();
}