Example usage for android.app NotificationManager cancel

List of usage examples for android.app NotificationManager cancel

Introduction

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

Prototype

public void cancel(int id) 

Source Link

Document

Cancel a previously shown notification.

Usage

From source file:com.embeddedlog.LightUpDroid.alarms.AlarmNotifications.java

public static void showLowPriorityNotification(Context context, AlarmInstance instance) {
    Log.v("Displaying low priority notification for alarm instance: " + instance.mId);
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    Resources resources = context.getResources();
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context)
            .setContentTitle(resources.getString(R.string.alarm_alert_predismiss_title))
            .setContentText(AlarmUtils.getAlarmText(context, instance))
            .setSmallIcon(R.drawable.stat_notify_alarm).setOngoing(false).setAutoCancel(false)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT).setCategory(NotificationCompat.CATEGORY_ALARM);

    // Setup up hide notification
    Intent hideIntent = AlarmStateManager.createStateChangeIntent(context, "DELETE_TAG", instance,
            AlarmInstance.HIDE_NOTIFICATION_STATE);
    notification.setDeleteIntent(PendingIntent.getBroadcast(context, instance.hashCode(), hideIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup up dismiss action
    Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, "DISMISS_TAG", instance,
            AlarmInstance.DISMISSED_STATE);
    notification.addAction(android.R.drawable.ic_menu_close_clear_cancel,
            resources.getString(R.string.alarm_alert_dismiss_now_text), PendingIntent.getBroadcast(context,
                    instance.hashCode(), dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    // Setup content action if instance is owned by alarm
    long alarmId = instance.mAlarmId == null ? Alarm.INVALID_ID : instance.mAlarmId;
    Intent viewAlarmIntent = Alarm.createIntent(context, DeskClock.class, alarmId);
    viewAlarmIntent.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.ALARM_TAB_INDEX);
    viewAlarmIntent.putExtra(AlarmClockFragment.SCROLL_TO_ALARM_INTENT_EXTRA, alarmId);
    viewAlarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notification.setContentIntent(PendingIntent.getActivity(context, instance.hashCode(), viewAlarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));

    nm.cancel(instance.hashCode());
    nm.notify(instance.hashCode(), notification.build());
}

From source file:com.tct.email.NotificationController.java

public void cancelFailStatusNotification(long accountId) {
    NotificationManager notificationManager = getInstance(mContext).mNotificationManager;
    notificationManager.cancel(getSendFailedNotificationId(accountId));
}

From source file:com.tct.email.NotificationController.java

public void cancelCalendarOrContactsNotification() {
    NotificationManager notificationManager = getInstance(mContext).mNotificationManager;
    notificationManager.cancel(NotificationController.EXCHANGE_NEWCALENDAR_NOTIFICATION_ID);
    notificationManager.cancel(NotificationController.EXCHANGE_NEWCONTACTS_NOTIFICATION_ID);
    notificationManager.cancel(NotificationController.EXCHANGE_NEWSTORAGE_NOTIFICATION_ID); //TS: zheng.zou 2016-1-22 EMAIL BUGFIX-1431088 ADD
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

private synchronized void hideClientNotification(ClientInfo ci) {
    if (ci.notificationId != 0) {
        NotificationManager nm = (NotificationManager) service.getSystemService(Service.NOTIFICATION_SERVICE);
        nm.cancel(ci.notificationId);
        ci.notificationId = 0;/*from  w w w .  j a  v a 2  s . co m*/
    }
}

From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.battery_info, root, false);

    mbattery_percent = (TextView) view.findViewById(R.id.batt_percent);
    mbattery_volt = (TextView) view.findViewById(R.id.batt_volt);
    mbattery_status = (TextView) view.findViewById(R.id.batt_status);
    mBattIcon = (ImageView) view.findViewById(R.id.batt_icon);

    if (new File(BAT_VOLT_PATH).exists()) {
        int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH));
        if (volt > 5000)
            volt = (int) Math.round(volt / 1000.0);// in microvolts
        mbattery_volt.setText(volt + " mV");
        mBattIcon.setVisibility(ImageView.GONE);
        mbattery_volt.setVisibility(TextView.VISIBLE);
        mbattery_volt.setOnClickListener(new View.OnClickListener() {
            @Override/*  w w  w.  j  av a2  s.c om*/
            public void onClick(View view) {
                Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null)
                    startActivity(powerUsageIntent);
            }
        });
        mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                mBattIcon.setVisibility(ImageView.VISIBLE);
                mbattery_volt.setVisibility(TextView.GONE);
                return true;
            }
        });
    } else {
        mBattIcon.setVisibility(ImageView.VISIBLE);
        mbattery_volt.setVisibility(TextView.GONE);
        mBattIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                    Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
                    startActivity(powerUsageIntent);
                } catch (Exception e) {
                }
            }
        });
    }

    SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider);
    if (new File(BLX_PATH).exists()) {
        no_settings = false;
        mBlxSlider.setMax(100);

        mBlxVal = (TextView) view.findViewById(R.id.blx_val);
        mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%");

        mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
        mBlxSlider.setOnSeekBarChangeListener(this);
        Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob);
        mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false));
        mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                final SharedPreferences.Editor editor = mPreferences.edit();
                editor.putBoolean(BLX_SOB, checked);
                if (checked) {
                    editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH)));
                }
                editor.commit();
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    mFastChargePath = Helpers.fastcharge_path();
    if (mFastChargePath != null) {
        no_settings = false;
        mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob);
        mFastchargeOnBoot.setChecked(
                mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1")));
        mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton v, boolean checked) {
                mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply();
                final NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                if (checked) {
                    new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath);
                    Notification n = new Notification.Builder(context)
                            .setContentTitle(context.getText(R.string.app_name))
                            .setContentText(context.getText(R.string.fast_charge_notification_title))
                            .setTicker(context.getText(R.string.fast_charge_notification_title))
                            .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis())
                            .getNotification();
                    //n.flags = Notification.FLAG_NO_CLEAR;
                    nm.notify(1337, n);
                } else {
                    new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath);
                    nm.cancel(1337);
                }
            }
        });
    } else {
        LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout);
        mpart.setVisibility(LinearLayout.GONE);
    }
    if (no_settings) {
        LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings);
        ns.setVisibility(LinearLayout.VISIBLE);
    }

    return view;
}

From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java

/**
 * Cancel and remove the persistent notification
 *//*from w w w.  ja v a 2s.c  o  m*/
private void cancelNotification() {
    NotificationManager notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
    if (notificationManager != null) {
        notificationManager.cancel(NOTIFICATION_ID);
    }
}

From source file:com.asksven.betterbatterystats.StatsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    super.onCreate(savedInstanceState);

    // HockeyApp//from   ww  w . j  a  va 2 s.c  o m
    try {
        MetricsManager.register(getApplication());
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
    }

    //Log.i(TAG, "OnCreated called");
    setContentView(R.layout.stats);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.app_name));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayUseLogoEnabled(false);

    // set debugging
    if (sharedPrefs.getBoolean("debug_logging", false)) {
        LogSettings.DEBUG = true;
        CommonLogSettings.DEBUG = true;
    } else {
        LogSettings.DEBUG = false;
        CommonLogSettings.DEBUG = false;
    }

    swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);

    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            doRefresh(true);
        }
    });

    ///////////////////////////////////////////////
    // check if we have a new release
    ///////////////////////////////////////////////
    // if yes do some migration (if required) and show release notes
    String strLastRelease = sharedPrefs.getString("last_release", "0");

    String strCurrentRelease = "";
    try {
        PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);

        strCurrentRelease = Integer.toString(pinfo.versionCode);
    } catch (Exception e) {
        // nop strCurrentRelease is set to ""
    }

    // Grant permissions if they are missing and root is available
    if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)
            || !SysUtils.hasPackageUsageStatsPermission(this)) {
        if ((RootShell.getInstance().isRooted())) {

            // attempt to set perms using pm-comand
            Log.i(TAG, "attempting to grant perms with 'pm grant'");

            String pkg = this.getPackageName();
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.BATTERY_STATS");
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.DUMP");
            RootShell.getInstance().run("pm grant " + pkg + " android.permission.PACKAGE_USAGE_STATS");

            if (SysUtils.hasBatteryStatsPermission(this)) {
                Log.i(TAG, "succeeded");
            } else {
                Log.i(TAG, "failed");
            }
        }
    }

    // Package usage stats were introduced in SDK21 so we need to make the distinction
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // show install as system app screen if root available but perms missing
        if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)
                || !SysUtils.hasPackageUsageStatsPermission(this)) {
            Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
            this.startActivity(intentSystemApp);
        }
    } else {
        if (!SysUtils.hasBatteryStatsPermission(this) || !SysUtils.hasDumpsysPermission(this)) {
            Intent intentSystemApp = new Intent(this, SystemAppActivity.class);
            this.startActivity(intentSystemApp);
        }

    }
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // first start
    if (strLastRelease.equals("0")) {

        boolean firstLaunch = !prefs.getBoolean("launched", false);

        if (firstLaunch) {
            // Save that the app has been launched
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("launched", true);
            editor.commit();

            // start service to persist reference
            Intent serviceIntent = new Intent(this, WriteUnpluggedReferenceService.class);
            this.startService(serviceIntent);

            // refresh widgets
            Intent intentRefreshWidgets = new Intent(LargeWidgetProvider.WIDGET_UPDATE);
            this.sendBroadcast(intentRefreshWidgets);

        }

        SharedPreferences.Editor updater = sharedPrefs.edit();
        updater.putString("last_release", strCurrentRelease);
        updater.commit();
    } else if (!strLastRelease.equals(strCurrentRelease)) {
        // save the current release to properties so that the dialog won't be shown till next version
        SharedPreferences.Editor updater = sharedPrefs.edit();
        updater.putString("last_release", strCurrentRelease);
        updater.commit();

        // we don't need to delete refs as long as we don't change the database schema
        //         Toast.makeText(this, getString(R.string.info_deleting_refs), Toast.LENGTH_SHORT).show();
        //         ReferenceStore.deleteAllRefs(this);
        //         Intent i = new Intent(this, WriteBootReferenceService.class);
        //         this.startService(i);
        //         i = new Intent(this, WriteUnpluggedReferenceService.class);
        //         this.startService(i);
        ChangeLog cl = new ChangeLog(this);
        cl.getLogDialog().show();

    }

    ///////////////////////////////////////////////
    // retrieve default selections for spinners
    // if none were passed
    ///////////////////////////////////////////////

    m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
    m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);

    if (!ReferenceStore.hasReferenceByName(m_refFromName, this)) {

        m_refFromName = Reference.BOOT_REF_FILENAME;
        Toast.makeText(this, getString(R.string.info_fallback_to_boot), Toast.LENGTH_SHORT).show();
    }

    if (LogSettings.DEBUG)
        Log.i(TAG, "onCreate state from preferences: refFrom=" + m_refFromName + " refTo=" + m_refToName);

    try {
        // recover any saved state
        if ((savedInstanceState != null) && (!savedInstanceState.isEmpty())) {
            m_iStat = (Integer) savedInstanceState.getSerializable("stat");
            m_refFromName = (String) savedInstanceState.getSerializable("stattypeFrom");
            m_refToName = (String) savedInstanceState.getSerializable("stattypeTo");

            if (LogSettings.DEBUG)
                Log.i(TAG,
                        "onCreate retrieved saved state: refFrom=" + m_refFromName + " refTo=" + m_refToName);

        }
    } catch (Exception e) {
        m_iStat = Integer.valueOf(sharedPrefs.getString("default_stat", "0"));
        m_refFromName = sharedPrefs.getString("default_stat_type", Reference.UNPLUGGED_REF_FILENAME);

        Log.e(TAG, "Exception: " + e.getMessage());
        DataStorage.LogToFile(LOGFILE, "Exception in onCreate restoring Bundle");
        DataStorage.LogToFile(LOGFILE, e.getMessage());
        DataStorage.LogToFile(LOGFILE, e.getStackTrace());

        Toast.makeText(this, getString(R.string.info_state_recovery_error), Toast.LENGTH_SHORT).show();
    }

    // Handle the case the Activity was called from an intent with paramaters
    Bundle extras = getIntent().getExtras();
    if ((extras != null) && !extras.isEmpty()) {
        // Override if some values were passed to the intent
        if (extras.containsKey(StatsActivity.STAT))
            m_iStat = extras.getInt(StatsActivity.STAT);
        if (extras.containsKey(StatsActivity.STAT_TYPE_FROM))
            m_refFromName = extras.getString(StatsActivity.STAT_TYPE_FROM);
        if (extras.containsKey(StatsActivity.STAT_TYPE_TO))
            m_refToName = extras.getString(StatsActivity.STAT_TYPE_TO);

        if (LogSettings.DEBUG)
            Log.i(TAG, "onCreate state from extra: refFrom=" + m_refFromName + " refTo=" + m_refToName);

        boolean bCalledFromNotification = extras.getBoolean(StatsActivity.FROM_NOTIFICATION, false);

        // Clear the notifications that was clicked to call the activity
        if (bCalledFromNotification) {
            NotificationManager nM = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
            nM.cancel(EventWatcherService.NOTFICATION_ID);
        }
    }

    // Spinner for selecting the stat
    Spinner spinnerStat = (Spinner) findViewById(R.id.spinnerStat);

    ArrayAdapter spinnerStatAdapter = ArrayAdapter.createFromResource(this, R.array.stats,
            R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item);
    spinnerStatAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); // android.R.layout.simple_spinner_dropdown_item);

    spinnerStat.setAdapter(spinnerStatAdapter);
    // setSelection MUST be called after setAdapter
    spinnerStat.setSelection(m_iStat);
    spinnerStat.setOnItemSelectedListener(this);

    ///////////////////////////////////////////////
    // Spinner for Selecting the Stat type
    ///////////////////////////////////////////////
    Spinner spinnerStatType = (Spinner) findViewById(R.id.spinnerStatType);
    m_spinnerFromAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item);
    m_spinnerFromAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item);
    spinnerStatType.setAdapter(m_spinnerFromAdapter);

    try {
        this.setListViewAdapter();
    } catch (BatteryInfoUnavailableException e) {
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        Snackbar.make(findViewById(android.R.id.content), R.string.info_service_connection_error,
                Snackbar.LENGTH_LONG).show();
        //         Toast.makeText(this,
        //               getString(R.string.info_service_connection_error),
        //               Toast.LENGTH_LONG).show();

    } catch (Exception e) {
        //Log.e(TAG, e.getMessage(), e.fillInStackTrace());
        Log.e(TAG, "Exception: " + Log.getStackTraceString(e));
        Toast.makeText(this, getString(R.string.info_unknown_stat_error), Toast.LENGTH_LONG).show();
    }
    // setSelection MUST be called after setAdapter
    spinnerStatType.setSelection(m_spinnerFromAdapter.getPosition(m_refFromName));
    spinnerStatType.setOnItemSelectedListener(this);

    ///////////////////////////////////////////////
    // Spinner for Selecting the end sample
    ///////////////////////////////////////////////
    Spinner spinnerStatSampleEnd = (Spinner) findViewById(R.id.spinnerStatSampleEnd);
    m_spinnerToAdapter = new ReferencesAdapter(this, R.layout.bbs_spinner_layout); //android.R.layout.simple_spinner_item);
    m_spinnerToAdapter.setDropDownViewResource(R.layout.bbs_spinner_dropdown_item); //android.R.layout.simple_spinner_dropdown_item);

    spinnerStatSampleEnd.setVisibility(View.VISIBLE);
    spinnerStatSampleEnd.setAdapter(m_spinnerToAdapter);
    // setSelection must be called after setAdapter
    if ((m_refToName != null) && !m_refToName.equals("")) {
        int pos = m_spinnerToAdapter.getPosition(m_refToName);
        spinnerStatSampleEnd.setSelection(pos);

    } else {
        spinnerStatSampleEnd.setSelection(m_spinnerToAdapter.getPosition(Reference.CURRENT_REF_FILENAME));
    }

    spinnerStatSampleEnd.setOnItemSelectedListener(this);

    ///////////////////////////////////////////////
    // sorting
    ///////////////////////////////////////////////
    m_iSorting = 0;

    // log reference store
    ReferenceStore.logReferences(this);

    if (LogSettings.DEBUG) {
        Log.i(TAG, "onCreate final state: refFrom=" + m_refFromName + " refTo=" + m_refToName);
        Log.i(TAG, "OnCreated end");
    }

}

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatcherService.java

private void patchFile(Bundle data) {
    Intent resultIntent = new Intent(this, MainActivity.class);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    resultIntent.setAction(Intent.ACTION_MAIN);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);

    final Notification.Builder builder = new Notification.Builder(this);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setOngoing(true);/*  w w w .j a v a2s .c  o m*/
    builder.setContentTitle(getString(R.string.overall_progress));
    builder.setContentIntent(pendingIntent);
    builder.setProgress(0, 0, true);

    final NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(1, builder.build());

    Patcher.ProgressListener listener = new Patcher.ProgressListener() {
        @Override
        public void onProgressUpdated(long bytes, long maxBytes) {
            updateProgress(bytes, maxBytes);
        }

        @Override
        public void onFilesUpdated(long files, long maxFiles) {
            builder.setContentText(String.format(getString(R.string.overall_progress_files), files, maxFiles));
            builder.setProgress((int) maxFiles, (int) files, false);
            nm.notify(1, builder.build());

            updateFiles(files, maxFiles);
        }

        @Override
        public void onDetailsUpdated(String text) {
            updateDetails(text);
        }
    };

    Bundle result = PatcherUtils.patchFile(this, data, listener);

    if (result != null) {
        String newFile = result.getString(PatcherUtils.RESULT_PATCH_FILE_NEW_FILE);
        int errorCode = result.getInt(PatcherUtils.RESULT_PATCH_FILE_ERROR_CODE);
        boolean failed = result.getBoolean(PatcherUtils.RESULT_PATCH_FILE_FAILED);
        onPatchedFile(failed, errorCode, newFile);
    }

    nm.cancel(1);
}

From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java

private void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);/*from   ww  w. jav a  2  s. co  m*/
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}

From source file:com.CPTeam.VselCalc.AutoUpdateApk.java

protected void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= NOTIFICATION_FLAGS;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);//  w w  w  .j  a v a 2 s  .c o m
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}