List of usage examples for android.app NotificationManager cancel
public void cancel(int id)
From source file:de.tudresden.inf.rn.mobilis.mxa.XMPPRemoteService.java
/** * Clear leftover notification in case this service previously got * killed while running./*ww w . jav a 2 s .c o m*/ * * @author Tobias Rho */ private void stopNotification() { if (RUN_IN_FOREGROUND) { stopForeground(true); } else { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.cancel(XMPPSERVICE_STATUS); } }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/* ww w. j a v a 2s. com*/ // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set title setTitle(String.format("%s - %s", getString(R.string.app_name), TextUtils.join(", ", mAppInfo.getApplicationName()))); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL(ActivityApp.this) + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); if (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true)) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy list view adapter final ExpandableListView lvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); lvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(R.layout.restrictionentry, mAppInfo, restrictionName, methodName); lvRestriction.setAdapter(mPrivacyListAdapter); if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); lvRestriction.expandGroup(groupPosition); lvRestriction.setSelectedGroup(groupPosition); if (methodName != null) { int childPosition = PrivacyManager.getHooks(restrictionName) .indexOf(new Hook(restrictionName, methodName)); lvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } // Annotate Meta.annotate(this); }
From source file:org.cryptsecure.Communicator.java
/** * Cancel notification./* w ww . ja v a 2s . c o m*/ * * @param context * the context * @param uid * the uid */ public static void cancelNotification(Context context, int uid) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = 8888888 + uid; notificationManager.cancel(notificationId); }
From source file:org.thoughtland.xlocation.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;/*from ww w . ja v a 2 s.c o m*/ // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set sub title getActionBar().setSubtitle(TextUtils.join(", ", mAppInfo.getApplicationName())); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL() + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); boolean isApp = PrivacyManager.isApplication(mAppInfo.getUid()); boolean odSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemandSystem, false); boolean gondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true); if ((isApp || odSystem) && gondemand) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy expandable list view adapter final ExpandableListView elvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); elvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(this, R.layout.restrictionentry, mAppInfo, restrictionName, methodName); elvRestriction.setAdapter(mPrivacyListAdapter); // Listen for group expand elvRestriction.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(final int groupPosition) { if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingMethodExpert, false)) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityApp.this); alertDialogBuilder.setTitle(R.string.app_name); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setMessage(R.string.msg_method_expert); alertDialogBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { PrivacyManager.setSetting(userId, PrivacyManager.cSettingMethodExpert, Boolean.toString(true)); } }); alertDialogBuilder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { elvRestriction.collapseGroup(groupPosition); } }); alertDialogBuilder.setCancelable(false); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } } }); // Go to method if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); elvRestriction.setSelectedGroup(groupPosition); elvRestriction.expandGroup(groupPosition); if (methodName != null) { Version version = new Version(Util.getSelfVersionName(this)); int childPosition = PrivacyManager.getHooks(restrictionName, version) .indexOf(new Hook(restrictionName, methodName)); elvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } }
From source file:com.ntsync.android.sync.syncadapter.SyncAdapter.java
private boolean processRestrictions(Restrictions currRestr, Restrictions newRestr, Account account) throws OperationApplicationException { boolean resync = false; if (newRestr != null && (currRestr == null || !currRestr.equals(newRestr))) { // Notify User. NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); if (currRestr != null && newRestr.isPhotoSyncSupported() && !currRestr.isPhotoSyncSupported()) { // Create ViewAccount-Intent Intent viewAccountsIntent = new Intent(mContext, ViewAccountsActivity.class); // Adds the back stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ViewAccountsActivity.class); stackBuilder.addNextIntent(viewAccountsIntent); // Photo sync possible. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(Constants.NOTIF_ICON) .setContentTitle(mContext.getText(R.string.notif_photosyncenabled_title).toString()) .setContentText(account.name).setAutoCancel(true).setOnlyAlertOnce(true) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); notificationManager.notify(Constants.NOTIF_PHOTO_SYNC_SUPPORTED, mBuilder.build()); // Resync to sync Photos resync = true;//from w w w . j a v a 2 s . c om setExplicitSavePhoto(account, true); } if (newRestr.isPhotoSyncSupported()) { notificationManager.cancel(Constants.NOTIF_PHOTO_NOT_SYNCED); } if (!newRestr.isPhotoSyncSupported()) { notificationManager.cancel(Constants.NOTIF_PHOTO_SYNC_SUPPORTED); } if (currRestr != null && newRestr.getMaxContactCount() != currRestr.getMaxContactCount()) { // Create ViewAccount-Intent Intent viewAccountsIntent = new Intent(mContext, ViewAccountsActivity.class); // Adds the back stack TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(ViewAccountsActivity.class); stackBuilder.addNextIntent(viewAccountsIntent); boolean moreAllowed = newRestr.getMaxContactCount() > currRestr.getMaxContactCount(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext) .setSmallIcon(Constants.NOTIF_ICON) .setContentTitle(moreAllowed ? getText(R.string.notif_contact_moresupported_title) : getText(R.string.notif_contact_lesssupported_title)) .setContentText(String.format(getText(R.string.notif_contact_supported_content), newRestr.getMaxContactCount(), account.name)) .setAutoCancel(true).setOnlyAlertOnce(true) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); notificationManager.notify(Constants.NOTIF_MAX_CONTACT_SUPPORTED, mBuilder.build()); // Hide Contacts not syned, but allow the message to show up // again if there are still more than allowed. notificationManager.cancel(Constants.NOTIF_CONTACTS_NOT_SYNCED); unhideMaxContactMessage(mContext, account); } if (resync) { ContactManager.setDirtyFlag(mContext, account); } SyncUtils.saveRestrictions(account, mAccountManager, newRestr); } return resync; }
From source file:jmri.enginedriver.threaded_application.java
void removeNotification() {
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(ED_NOTIFICATION_ID);
}
From source file:org.nerdcircus.android.klaxon.Notifier.java
@Override public void onReceive(Context context, Intent intent) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); if (intent.getAction().equals(Pager.PAGE_RECEIVED)) { Log.d(TAG, "new page received. notifying."); //get subject line of page, for notification. Cursor cursor = context.getContentResolver().query(intent.getData(), new String[] { Pager.Pages._ID, Pager.Pages.SUBJECT }, null, null, null); cursor.moveToFirst();/*from w w w . ja v a2s . com*/ String page_subj = cursor.getString(cursor.getColumnIndex(Pager.Pages.SUBJECT)); Notification n = getNotification(context, page_subj); n.sound = null; //no noise initially. wait for the delayed ANNOY action below. nm.notify(R.string.notify_page, n); Intent i = new Intent(Pager.ANNOY_ACTION); //we cant use data here, because it makes the silencing fail. i.putExtra("notification_text", page_subj); PendingIntent annoyintent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Log.d(TAG, "notifcation interval: " + prefs.getString("notification_interval", "unknown")); long repeat_interval_ms = Integer.valueOf(prefs.getString("notification_interval", "20000")) .longValue(); Log.d(TAG, "notifcation interval: " + repeat_interval_ms); // 500 ms delay, to prevent the regular text message noise from stomping on us. am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500, repeat_interval_ms, annoyintent); } else if (intent.getAction().equals(Pager.SILENCE_ACTION)) { Log.d(TAG, "cancelling the notification..."); Intent i = new Intent(Pager.ANNOY_ACTION); PendingIntent annoyintent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); am.cancel(annoyintent); nm.cancel(R.string.notify_page); } else if (intent.getAction().equals(Pager.ANNOY_ACTION)) { Log.e(TAG, "got annoy intent. annoying."); //just be annoying. Notification n = getNotification(context, intent.getStringExtra("notification_text")); nm.notify(R.string.notify_page, n); } else if (intent.getAction().equals("org.nerdcircus.android.klaxon.REPLY_SENT")) { //a reply was sent. update state in the db. if (Activity.RESULT_OK == getResultCode()) { Log.d(TAG, "reply successful. updating ack status.."); //result was sent. update state. updateAckStatus(context, intent.getData(), intent.getIntExtra(Pager.EXTRA_NEW_ACK_STATUS, 0)); } else { Log.e(TAG, "reply failed!!! doing nothing."); } } else { Log.e(TAG, "Uncaught Action:" + intent.getAction()); } }
From source file:org.restcomm.android.sdk.RCDevice.java
void onNotificationIntent(Intent intent) { String intentAction = intent.getAction(); //if (!intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) { if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT) || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO) || intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO) || intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE) || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) { // The user has acted on a call notification, let's cancel it String username = intent.getStringExtra(EXTRA_DID).replaceAll(".*?sip:", "").replaceAll("@.*$", ""); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(callNotifications.get(username)); //callNotifications.remove(username); activeCallNotification = false;/*w w w . jav a2 s . co m*/ } Intent actionIntent = null; /* if (intentAction.equals(ACTION_NOTIFICATION_CALL_OPEN)) { RCConnection connection = getLiveConnection(); if (connection != null) { if (connection.isIncoming()) { callIntent.setAction(ACTION_INCOMING_CALL); } else { callIntent.setAction(ACTION_OUTGOING_CALL); } callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // don't forget to copy the extras to callIntent callIntent.putExtras(intent); actionIntent = callIntent; } } */ if (intentAction.equals(ACTION_NOTIFICATION_CALL_DEFAULT)) { if (callIntent != null) { callIntent.setAction(ACTION_INCOMING_CALL); // don't forget to copy the extras to callIntent callIntent.putExtras(intent); actionIntent = callIntent; } else { Context context = getApplicationContext(); PackageManager packageManager = context.getPackageManager(); actionIntent = packageManager.getLaunchIntentForPackage(context.getPackageName()); } } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_VIDEO)) { callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_VIDEO); // don't forget to copy the extras callIntent.putExtras(intent); actionIntent = callIntent; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_ACCEPT_AUDIO)) { callIntent.setAction(ACTION_INCOMING_CALL_ANSWER_AUDIO); // don't forget to copy the extras callIntent.putExtras(intent); actionIntent = callIntent; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DECLINE) || intentAction.equals(ACTION_NOTIFICATION_CALL_DELETE)) { RCConnection pendingConnection = getPendingConnection(); if (pendingConnection != null) { pendingConnection.reject(); } release(); // if the call has been requested to be declined, we shouldn't do any UI handling return; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_MUTE_AUDIO)) { RCConnection liveConnection = getLiveConnection(); if (liveConnection != null) { if (liveConnection.isAudioMuted()) { liveConnection.setAudioMuted(false); } else { liveConnection.setAudioMuted(true); } } // if the call has been requested to be muted, we shouldn't do any UI handling return; } else if (intentAction.equals(ACTION_NOTIFICATION_CALL_DISCONNECT)) { RCConnection liveConnection = getLiveConnection(); if (liveConnection != null) { liveConnection.disconnect(); if (!isAttached()) { // if the call has been requested to be disconnected, we shouldn't do any UI handling callIntent.setAction(ACTION_CALL_DISCONNECT); //callIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); actionIntent = callIntent; startActivity(actionIntent); } /* // Important if we just trigger the call intent, then after the call is disconnected we will land to the previous screen in // that Task Stack, which is not what we want. Instead, we want the call activity to be finished and to just remain where // we were. To do that we need to create a new Task Stack were we only place the call activity TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(actionIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); try { resultPendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } */ } return; } else if (intentAction.equals(ACTION_NOTIFICATION_MESSAGE_DEFAULT)) { if (messageIntent == null) { storageManagerPreferences = new StorageManagerPreferences(this); String messageIntentString = storageManagerPreferences .getString(RCDevice.ParameterKeys.INTENT_INCOMING_MESSAGE, null); if (messageIntentString != null) { try { messageIntent = Intent.parseUri(messageIntentString, Intent.URI_INTENT_SCHEME); //service was stopped and user taps on Notification case if (!isInitialized()) { HashMap<String, Object> parameters = StorageUtils.getParams(storageManagerPreferences); try { initialize(null, parameters, null); } catch (RCException e) { RCLogger.e(TAG, e.toString()); } } } catch (URISyntaxException e) { throw new RuntimeException("Failed to handle Notification"); } } } messageIntent.setAction(ACTION_INCOMING_MESSAGE); // don't forget to copy the extras messageIntent.putExtras(intent); actionIntent = messageIntent; //we want to stop foreground (notification is tapped) stopForeground(true); stopRepeatingTask(); } else { throw new RuntimeException("Failed to handle Notification"); } // We need to create a Task Stack to make sure we maintain proper flow at all times TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds either call or message intent's Component in the stack together with all its parent activities (remember that for this to work the App Manifest needs to describe their relationship) stackBuilder.addParentStack(actionIntent.getComponent()); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(actionIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); try { resultPendingIntent.send(); } catch (PendingIntent.CanceledException e) { throw new RuntimeException("Pending Intent cancelled", e); } }
From source file:org.restcomm.android.sdk.RCDevice.java
void onNotificationCallCanceled(RCConnection connection) { if (activeCallNotification) { // Peer has canceled the call and there's an active call ringing, we need to cancel the notification String peerUsername = connection.getPeer().replaceAll(".*?sip:", "").replaceAll("@.*$", ""); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); //There's no peer username provided in Push Notification Message, so //the callNotifications map cannot be populated with the right key notificationManager.cancel(callNotifications.get(peerUsername)); // And then create a new notification to show that the call is missed, together with a means to call the peer. Notice // that if this notification is tapped, the peer will be called using the video preference of callIntent.setAction(ACTION_OUTGOING_CALL); callIntent.putExtra(RCDevice.EXTRA_DID, peerUsername); callIntent.putExtra(RCDevice.EXTRA_VIDEO_ENABLED, (connection.getRemoteMediaType() == RCConnection.ConnectionMediaType.AUDIO_VIDEO)); // We need to create a Task Stack to make sure we maintain proper flow at all times TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds either call or message intent's Component in the stack together with all its parent activities (remember that for this to work the App Manifest needs to describe their relationship) stackBuilder.addParentStack(callIntent.getComponent()); // Adds the target Intent to the top of the stack stackBuilder.addNextIntent(callIntent); // Gets a PendingIntent containing the entire back stack, but with Component as the active Activity PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Service is not attached to an activity, let's use a notification instead NotificationCompat.Builder builder = getNotificationBuilder(true); builder.setSmallIcon(R.drawable.ic_phone_missed_24dp) .setContentTitle(connection.getPeer().replaceAll(".*?sip:", "").replaceAll("@.*$", "")) .setContentText("Missed call") //.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.ringing_sample)) // audioManager.getResourceIdForKey(ParameterKeys.RESOURCE_SOUND_RINGING))) // Need this to show up as Heads-up Notification .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true) // cancel notification when user acts on it (Important: only applies to default notification area, not additional actions) .setContentIntent(resultPendingIntent); Notification notification = builder.build(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { //we need to stop foreground notification //if we leave it, the notification 'Missed call' will not be dismissible //because foreground notificaiton is shown for id: callNotifications.get(peerUsername) stopForeground(true);/*from w w w . j av a 2s . com*/ } notificationManager.notify(callNotifications.get(peerUsername), notification); // Remove the call notification, as it will be removed automatically //callNotifications.remove(peerUsername); activeCallNotification = false; } }