List of usage examples for android.app NotificationManager cancelAll
public void cancelAll()
From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java
/** * Clear all notifications without canceling repeating alarms */// w w w. j a v a 2 s.co m public void clearAll() { SharedPreferences settings = getSharedPreferences(); NotificationManager nc = getNotificationManager(); Map<String, ?> alarms = settings.getAll(); Set<String> alarmIds = alarms.keySet(); for (String alarmId : alarmIds) { clear(alarmId); } nc.cancelAll(); }
From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java
/** * Cancel all notifications that were created by this plugin. * * Android can only unregister a specific alarm. There is no such thing * as cancelAll. Therefore we rely on the Shared Preferences which holds * all our alarms to loop through these alarms and unregister them one * by one.//from w ww . j a v a 2 s.c o m */ public void cancelAll() { SharedPreferences settings = getSharedPreferences(); NotificationManager nc = getNotificationManager(); Map<String, ?> alarms = settings.getAll(); Set<String> alarmIds = alarms.keySet(); for (String alarmId : alarmIds) { cancel(alarmId); } nc.cancelAll(); }
From source file:com.wifiafterconnect.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancelAll(); wifiTools = WifiTools.getInstance(this); if (getIntent().getAction().equals(getString(R.string.action_reenable_wifi))) { wifiTools.enableWifi();/*from w w w . j a v a2 s .c o m*/ finish(); return; } setContentView(R.layout.main_activity); toggleWifi = (ToggleButton) findViewById(R.id.toggleWifi); // toggleWifi.setEnabled(checkCallingOrSelfPermission("android.permission.CHANGE_NETWORK_STATE") // == PackageManager.PERMISSION_GRANTED); buttonAuthenticateNow = (Button) findViewById(R.id.buttonAuthenticateNow); lvRememberedSites = (ListView) findViewById(R.id.listKnownSites); deleteSelected = (Button) findViewById(R.id.buttonDeleteSelected); inetStatusInd = (TextView) findViewById(R.id.textInetStatusInd); // Create an empty adapter we will use to display the loaded data. // We pass null for the cursor, then update it in onLoadFinished() adapter = new WifiSitesCursorAdapter(this); lvRememberedSites.setAdapter(adapter); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getSupportLoaderManager().initLoader(0, null, this); // WE would really like to keep track of connectivity state so that our buttons // reflect the state correctly IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); receiverWifiConnect = new WifiBroadcastReceiver() { @Override public void onWifiConnectivityChange(Context context, boolean connected) { refreshStatusIndicators(); } }; registerReceiver(receiverWifiConnect, intentFilter); // finally let us check if the device is connected to Internet presently checkInetOnline(); }
From source file:com.chen.mail.utils.NotificationUtils.java
/** * Get all notifications for all accounts, optionally cancel them, and repost. * This happens when locale changes. If you only want to resend messages from one * account-folder pair, pass in the account and folder that should be resent. * All other account-folder pairs will not have their notifications resent. * All notifications will be resent if account or folder is null. * * @param context Current context./*from w ww . j a va 2s .c o m*/ * @param cancelExisting True, if all notifications should be canceled before resending. * False, otherwise. * @param accountUri The {@link Uri} of the {@link Account} of the notification * upon which an action occurred. * @param folderUri The {@link Uri} of the {@link Folder} of the notification * upon which an action occurred. */ public static void resendNotifications(Context context, final boolean cancelExisting, final Uri accountUri, final FolderUri folderUri) { LogUtils.d(LOG_TAG, "resendNotifications "); if (cancelExisting) { LogUtils.d(LOG_TAG, "resendNotifications - cancelling all"); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.cancelAll(); } // Re-validate the notifications. final NotificationMap notificationMap = getNotificationMap(context); final Set<NotificationKey> keys = notificationMap.keySet(); for (NotificationKey notification : keys) { final Folder folder = notification.folder; final int notificationId = getNotificationId(notification.account.getAccountManagerAccount(), folder); // Only resend notifications if the notifications are from the same folder // and same account as the undo notification that was previously displayed. if (accountUri != null && !Objects.equal(accountUri, notification.account.uri) && folderUri != null && !Objects.equal(folderUri, folder.folderUri)) { LogUtils.d(LOG_TAG, "resendNotifications - not resending %s / %s" + " because it doesn't match %s / %s", notification.account.uri, folder.folderUri, accountUri, folderUri); continue; } LogUtils.d(LOG_TAG, "resendNotifications - resending %s / %s", notification.account.uri, folder.folderUri); final NotificationActionUtils.NotificationAction undoableAction = NotificationActionUtils.sUndoNotifications .get(notificationId); if (undoableAction == null) { validateNotifications(context, folder, notification.account, true, false, notification); } else { // Create an undo notification NotificationActionUtils.createUndoNotification(context, undoableAction); } } }
From source file:kr.co.cashqc.MainActivity.java
@Override protected void onResume() { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancelAll(); super.onResume(); // Check device for Play Services APK. }
From source file:org.apps8os.motivator.services.NotificationService.java
@Override protected void onHandleIntent(Intent intent) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean(SettingsActivity.KEY_SEND_NOTIFICATIONS, true)) { // Set up the notification with a builder NotificationCompat.Builder builder = new NotificationCompat.Builder(this); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Bundle extras = intent.getExtras(); // Check the notification type. int notificationType = extras.getInt(NOTIFICATION_TYPE); if (notificationType == NOTIFICATION_MOOD) { // Cancel all previous notifications. manager.cancelAll(); SprintDataHandler dataHandler = new SprintDataHandler(this); Sprint currentSprint = dataHandler.getCurrentSprint(); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // If there is no current sprint, cancel alarms. if (currentSprint == null) { Sprint latestEndedSprint = dataHandler.getLatestEndedSprint(); if (latestEndedSprint != null) { if (latestEndedSprint.endedYesterday()) { builder.setContentTitle(getString(R.string.completed_sprint)); builder.setSmallIcon(R.drawable.ic_stat_notification_icon_1); builder.setAutoCancel(true); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingResultIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(pendingResultIntent); manager.notify(NOTIFICATION_ID_SPRINT_ENDED, builder.build()); }/* www . jav a 2 s . c o m*/ } Intent notificationIntent = new Intent(this, NotificationService.class); PendingIntent pendingNotificationIntent = PendingIntent.getService(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.cancel(pendingNotificationIntent); } else { builder.setContentTitle(getString(R.string.today_screen_mood)); int currentDateInSprint = currentSprint.getCurrentDayOfTheSprint(); builder.setSmallIcon(R.drawable.ic_stat_notification_icon_1); // Remove the notification when the user clicks it. builder.setAutoCancel(true); // Where to go when user clicks the notification Intent resultIntent = new Intent(this, MoodQuestionActivity.class); DayDataHandler moodDataHandler = new DayDataHandler(this); // Check if there were events yesterday. DayInHistory yesterday = moodDataHandler.getDayInHistory( System.currentTimeMillis() - TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS)); yesterday.setEvents(); ArrayList<MotivatorEvent> yesterdayEvents = yesterday.getUncheckedEvents(this); if (!yesterdayEvents.isEmpty()) { // Put the events as extras to the intent so that we can pass them to the checking activity. resultIntent.putExtra(MotivatorEvent.YESTERDAYS_EVENTS, yesterdayEvents); resultIntent.putExtra(EventDataHandler.EVENTS_TO_CHECK, true); builder.setContentText(getString(R.string.you_had_an_event_yesterday)); } else { // No events to check. resultIntent.putExtra(EventDataHandler.EVENTS_TO_CHECK, false); EventDataHandler eventHandler = new EventDataHandler(this); long lastAddedEventTimestamp = eventHandler.getLatestAddedEventTimestamp(); if (lastAddedEventTimestamp != 0L && System.currentTimeMillis() - lastAddedEventTimestamp > TimeUnit.MILLISECONDS.convert(7, TimeUnit.DAYS)) { builder.setContentText(getString(R.string.plan_reminder)); } else { builder.setContentText(getString(R.string.today_is_the_day) + " " + currentDateInSprint + "/" + currentSprint.getDaysInSprint() + " - " + currentSprint.getSprintTitle()); } } // Preserve the normal navigation of the app by adding the parent stack of the result activity TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MoodQuestionActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingResultIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(pendingResultIntent); manager.notify(NOTIFICATION_ID_MOOD, builder.build()); } } else if (notificationType == NOTIFICATION_EVENT_START) { // Set up a notification for the start of an event. int eventId = extras.getInt(EventDataHandler.EVENT_ID); String eventName = extras.getString(EventDataHandler.EVENT_NAME); builder.setContentTitle(getString(R.string.you_have_an_event_starting)); builder.setContentText(eventName); builder.setSmallIcon(R.drawable.ic_stat_notification_icon_1); // Remove the notification when the user clicks it. builder.setAutoCancel(true); Intent resultIntent = new Intent(this, EventDetailsActivity.class); resultIntent.putExtra(EventDataHandler.EVENT_ID, eventId); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(EventDetailsActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingResultIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingResultIntent); manager.notify(eventId, builder.build()); } else if (notificationType == NOTIFICATION_EVENT_END) { // Set up a notification for the start of an event. int eventId = extras.getInt(EventDataHandler.EVENT_ID); builder.setContentTitle(getString(R.string.event_ending)); builder.setContentText(getString(R.string.go_home)); builder.setSmallIcon(R.drawable.ic_stat_notification_icon_1); // Remove the notification when the user clicks it. builder.setAutoCancel(true); Intent resultIntent = new Intent(this, EventDetailsActivity.class); resultIntent.putExtra(EventDataHandler.EVENT_ID, eventId); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(EventDetailsActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingResultIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingResultIntent); manager.notify(eventId + 10000, builder.build()); } } }
From source file:io.scalac.locationprovider.SendMockLocationService.java
/** * Remove all notifications from the notification bar. *///from ww w . ja va 2s . c o m private void removeNotification() { // An instance of NotificationManager is needed to remove notifications NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Remove all notifications notificationManager.cancelAll(); }
From source file:org.lyricue.android.Lyricue.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.settings_menu: Intent settingsActivity = new Intent(getBaseContext(), Preferences.class); startActivity(settingsActivity); return true; case R.id.profile_menu: SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = settings.edit(); editor.putString("profile", ""); editor.commit();/* ww w. j a va2 s .co m*/ getPrefs(); return true; case R.id.server_menu: Intent serverActivity = new Intent(getBaseContext(), ServerActivity.class); if (profile.equals("#demo")) { serverActivity.putExtra("host", "#demo"); } else { Log.i(TAG, "selecting " + hosts[0].toString()); serverActivity.putExtra("host", hosts[0].toString()); } serverActivity.putExtra("profile", profile); startActivity(serverActivity); return true; case R.id.exit_menu: NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); finish(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:net.jpuderer.android.bluedoor.DoorlockService.java
private void updateNotification() { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); if ((mConnectionState != STATE_CONNECTED) || (mDoorState == DOOR_STATE_UNKNOWN)) { notificationManager.cancelAll(); return;/* w ww.ja va 2 s . c o m*/ } Intent intent = new Intent(this, DoorlockService.class); Notification notification; if (mDoorState == DOOR_STATE_LOCKED) { intent.setAction(ACTION_UNLOCK); PendingIntent pIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), intent, 0); notification = new Notification.Builder(this).setContentTitle("Door is locked") .setContentText("Press to unlock").setSmallIcon(R.drawable.ic_door_locked) .setColor(getResources().getColor(android.R.color.holo_red_dark)).setContentIntent(pIntent) .setOngoing(true).build(); } else { intent.setAction(ACTION_UNLOCK); PendingIntent pIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), intent, 0); notification = new Notification.Builder(this).setContentTitle("Door is unlocked") .setContentText("Press to lock").setSmallIcon(R.drawable.ic_door_unlocked) .setColor(getResources().getColor(android.R.color.holo_green_dark)).setContentIntent(pIntent) .setOngoing(true).build(); } notificationManager.notify(0, notification); }
From source file:de.baumann.hhsmoodle.popup.Popup_todo.java
private void setTodoList() { PreferenceManager.setDefaultValues(Popup_todo.this, R.xml.user_settings, false); final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Popup_todo.this); NotificationManager nMgr = (NotificationManager) Popup_todo.this .getSystemService(Context.NOTIFICATION_SERVICE); nMgr.cancelAll(); //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "todo_title", "todo_content", "todo_creation" }; final String search = sharedPref.getString("filter_todo_subject", ""); final Cursor row = db.fetchDataByFilter(search, "todo_title"); final SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_todo.this, layoutstyle, row, column, xml_id, 0) {/* ww w . jav a 2 s . c o m*/ @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title")); final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content")); final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon")); final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment")); final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes); switch (todo_icon) { case "3": iv_icon.setImageResource(R.drawable.circle_green); break; case "2": iv_icon.setImageResource(R.drawable.circle_yellow); break; case "1": iv_icon.setImageResource(R.drawable.circle_red); break; } switch (todo_attachment) { case "true": iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.alert_circle); break; default: iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.alert_circle_red); int n = Integer.valueOf(_id); android.content.Intent iMain = new android.content.Intent(); iMain.setAction("shortcutToDo"); iMain.setClassName(Popup_todo.this, "de.baumann.hhsmoodle.activities.Activity_splash"); PendingIntent piMain = PendingIntent.getActivity(Popup_todo.this, n, iMain, 0); NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(Popup_todo.this) .setSmallIcon(R.drawable.school) .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary)) .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain); Notification notification = new NotificationCompat.Builder(Popup_todo.this) .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary)) .setSmallIcon(R.drawable.school).setContentTitle(todo_title) .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true) .setGroup("HHS_Moodle") .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content)) .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build(); NotificationManager notificationManager = (NotificationManager) Popup_todo.this .getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(n, notification); notificationManager.notify(0, builderSummary.build()); break; } iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final Item[] items = { new Item(getString(R.string.note_priority_0), R.drawable.circle_green), new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow), new Item(getString(R.string.note_priority_2), R.drawable.circle_red), }; ListAdapter adapter = new ArrayAdapter<Item>(Popup_todo.this, android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(Popup_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), todo_title, todo_content, "3", todo_attachment, todo_creation); setTodoList(); } else if (item == 1) { db.update(Integer.parseInt(_id), todo_title, todo_content, "2", todo_attachment, todo_creation); setTodoList(); } else if (item == 2) { db.update(Integer.parseInt(_id), todo_title, todo_content, "1", todo_attachment, todo_creation); setTodoList(); } } }).show(); } }); iv_attachment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { switch (todo_attachment) { case "true": db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "", todo_creation); setTodoList(); break; default: db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true", todo_creation); setTodoList(); break; } } }); return v; } }; lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title")); final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content")); final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon")); final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment")); final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation")); sharedPref.edit().putString("toDo_title", todo_title).apply(); sharedPref.edit().putString("toDo_text", todo_content).apply(); sharedPref.edit().putString("toDo_seqno", _id).apply(); sharedPref.edit().putString("toDo_icon", todo_icon).apply(); sharedPref.edit().putString("toDo_create", todo_creation).apply(); sharedPref.edit().putString("toDo_attachment", todo_attachment).apply(); helper_main.switchToActivity(Popup_todo.this, Activity_todo.class, false); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title")); final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content")); final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon")); final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment")); final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation")); final CharSequence[] options = { getString(R.string.bookmark_edit_title), getString(R.string.todo_share), getString(R.string.bookmark_createNote), getString(R.string.bookmark_createEvent), getString(R.string.bookmark_remove_bookmark) }; new AlertDialog.Builder(Popup_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.bookmark_edit_title))) { AlertDialog.Builder builder = new AlertDialog.Builder(Popup_todo.this); View dialogView = View.inflate(Popup_todo.this, R.layout.dialog_edit_title, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setHint(R.string.bookmark_edit_title); edit_title.setText(todo_title); builder.setView(dialogView); builder.setTitle(R.string.bookmark_edit_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); db.update(Integer.parseInt(_id), inputTag, todo_content, todo_icon, todo_attachment, todo_creation); setTodoList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(Popup_todo.this, edit_title); } if (options[item].equals(getString(R.string.todo_share))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.note_share_2)))); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { Intent calIntent = new Intent(Intent.ACTION_INSERT); calIntent.setType("vnd.android.cursor.item/event"); calIntent.putExtra(CalendarContract.Events.TITLE, todo_title); calIntent.putExtra(CalendarContract.Events.DESCRIPTION, todo_content); startActivity(calIntent); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setTodoList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.bookmark_createNote))) { sharedPref.edit().putString("handleTextTitle", todo_title) .putString("handleTextText", todo_content).apply(); helper_main.switchToActivity(Popup_todo.this, Activity_EditNote.class, false); } } }).show(); return true; } }); if (lv.getAdapter().getCount() == 0) { new android.app.AlertDialog.Builder(this) .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry))) .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }).show(); new Handler().postDelayed(new Runnable() { public void run() { finish(); } }, 2000); } }