List of usage examples for android.app PendingIntent getActivity
public static PendingIntent getActivity(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:org.wso2.emm.agent.services.operation.OperationManager.java
/** * Lock the device./*from w w w . j av a 2 s.co m*/ * * @param operation - Operation object. */ public void lockDevice(org.wso2.emm.agent.beans.Operation operation) throws AndroidAgentException { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); JSONObject inputData; String message = null; boolean isHardLockEnabled = false; try { if (operation.getPayLoad() != null) { inputData = new JSONObject(operation.getPayLoad().toString()); message = inputData.getString(Constants.ADMIN_MESSAGE); isHardLockEnabled = inputData.getBoolean(Constants.IS_HARD_LOCK_ENABLED); } } catch (JSONException e) { operation.setStatus(resources.getString(R.string.operation_value_error)); operation.setOperationResponse("Error in parsing LOCK payload."); resultBuilder.build(operation); throw new AndroidAgentException("Invalid JSON format.", e); } if (isHardLockEnabled && Constants.SYSTEM_APP_ENABLED) { if (message == null || message.isEmpty()) { message = resources.getString(R.string.txt_lock_activity); } Preference.putBoolean(context, Constants.IS_LOCKED, true); Preference.putString(context, Constants.LOCK_MESSAGE, message); operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); enableHardLock(message, operation); } else { operation.setStatus(resources.getString(R.string.operation_value_completed)); resultBuilder.build(operation); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.alert_message)) .setContentText(message).setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(), 0)); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, mBuilder.build()); devicePolicyManager.lockNow(); } if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Device locked"); } }
From source file:co.beem.project.beem.FbTextService.java
public void startForeGroundWithnotification(int statusStringId) { // Notification note=new Notification(R.drawable.ic_stat_pending_notification, // getString(R.string.notification_welcome), // System.currentTimeMillis()); isStartingForeground = true;/*from w ww . j a v a2 s . com*/ Intent i = new Intent(this, FbTextMainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); if (statusStringId == 0) { int statusState = mSettings.getInt(FbTextApplication.STATUS_KEY, 0); statusStringId = statusState == 0 ? R.string.notification_online : R.string.notification_invisible; } Notification note = new NotificationCompat.Builder(this).setContentTitle(getString(statusStringId)) .setContentText(getString(R.string.notification_description)) .setSmallIcon(R.drawable.ic_stat_pending_notification).setContentIntent(pi).build(); /*note.setLatestEventInfo(this, getString(statusStringId), getString(R.string.notification_description), pi);*/ note.flags |= Notification.FLAG_NO_CLEAR; startForeground(1080, note); }
From source file:com.raceyourself.android.samsung.ProviderService.java
private void enableIcon() { if (iconEnabled) return;//w ww . ja v a 2s . c o m iconEnabled = true; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.rylogo) .setContentTitle(getString(R.string.notification_title)) .setContentText(getString(R.string.notification_message)); Intent intent = new Intent(this, PopupActivity.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // Gets an instance of the NotificationManager service NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Builds the notification and issues it. mNotifyMgr.notify(TETHER_NOTIFICATION_ID, mBuilder.build()); }
From source file:com.safecell.HomeScreenActivity.java
public void showNotification(String msg) { if (!new ConfigurePreferences(contextHomeScreenActivity).getTripStrated()) { Notification notification = new Notification(R.drawable.launch_icon, "Notify", System.currentTimeMillis()); notification.setLatestEventInfo(HomeScreenActivity.this, "SafeCell", msg, PendingIntent.getActivity( HomeScreenActivity.this.getBaseContext(), 0, null, PendingIntent.FLAG_CANCEL_CURRENT)); mManager.notify(APP_ID, notification); }/*from w w w. jav a 2 s . c o m*/ }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
public static void notifySecondMentions(Context context, int secondAccount) { MentionsDataSource data = MentionsDataSource.getInstance(context); int numberNew = data.getUnreadCount(secondAccount); int smallIcon = R.drawable.ic_stat_icon; Bitmap largeIcon;//from w w w .j a v a 2s . c o m Intent resultIntent = new Intent(context, SwitchAccountsRedirect.class); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, 0); NotificationCompat.Builder mBuilder; String title = context.getResources().getString(R.string.app_name) + " - " + context.getResources().getString(R.string.sec_acc); ; String name = null; String message; String messageLong; String tweetText = null; NotificationCompat.Action replyAction = null; if (numberNew == 1) { name = data.getNewestName(secondAccount); SharedPreferences sharedPrefs = context.getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); // if they are muted, and you don't want them to show muted mentions // then just quit if (sharedPrefs.getString("muted_users", "").contains(name) && !sharedPrefs.getBoolean("show_muted_mentions", false)) { return; } message = context.getResources().getString(R.string.mentioned_by) + " @" + name; tweetText = data.getNewestMessage(secondAccount); messageLong = "<b>@" + name + "</b>: " + tweetText; largeIcon = getImage(context, name); Intent reply = new Intent(context, NotificationComposeSecondAcc.class); sharedPrefs.edit().putString("from_notification_second", "@" + name).commit(); long id = data.getLastIds(secondAccount)[0]; PendingIntent replyPending = PendingIntent.getActivity(context, 0, reply, 0); sharedPrefs.edit().putLong("from_notification_long_second", id).commit(); sharedPrefs.edit() .putString("from_notification_text_second", "@" + name + ": " + TweetLinkUtils.removeColorHtml(tweetText, AppSettings.getInstance(context))) .commit(); // Create the remote input RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("@" + name + " ").build(); // Create the notification action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_action_reply_dark, context.getResources().getString(R.string.noti_reply), replyPending).addRemoteInput(remoteInput) .build(); } else { // more than one mention message = numberNew + " " + context.getResources().getString(R.string.new_mentions); messageLong = "<b>" + context.getResources().getString(R.string.mentions) + "</b>: " + numberNew + " " + context.getResources().getString(R.string.new_mentions); largeIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawer_user_dark); } Intent markRead = new Intent(context, MarkReadSecondAccService.class); PendingIntent readPending = PendingIntent.getService(context, 0, markRead, 0); AppSettings settings = AppSettings.getInstance(context); Intent deleteIntent = new Intent(context, NotificationDeleteReceiverTwo.class); mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(TweetLinkUtils.removeColorHtml(message, settings)).setSmallIcon(smallIcon) .setLargeIcon(largeIcon).setContentIntent(resultPendingIntent).setAutoCancel(true) .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0)) .setPriority(NotificationCompat.PRIORITY_HIGH); if (numberNew == 1) { mBuilder.addAction(replyAction); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(Html.fromHtml( settings.addonTheme ? messageLong.replaceAll("FF8800", settings.accentColor) : messageLong))); } else { NotificationCompat.InboxStyle inbox = getMentionsInboxStyle(numberNew, secondAccount, context, TweetLinkUtils.removeColorHtml(message, settings)); mBuilder.setStyle(inbox); } if (settings.vibrate) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } if (settings.sound) { try { mBuilder.setSound(Uri.parse(settings.ringtone)); } catch (Exception e) { mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } } if (settings.led) mBuilder.setLights(0xFFFFFF, 1000, 1000); if (settings.notifications) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); notificationManager.notify(9, mBuilder.build()); // if we want to wake the screen on a new message if (settings.wakeScreen) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG"); wakeLock.acquire(5000); } // Pebble notification if (context .getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE) .getBoolean("pebble_notification", false)) { sendAlertToPebble(context, title, messageLong); } // Light Flow notification sendToLightFlow(context, title, messageLong); } }
From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java
private void SendNotification(String tickerText, String expandedText) { NotificationManager notificationManager = (NotificationManager) contextWrapper .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.ateamlogo; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.flags |= (Notification.FLAG_INSISTENT | Notification.FLAG_AUTO_CANCEL); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; Context context = contextWrapper.getApplicationContext(); // Intent to launch an activity when the extended text is clicked Intent intent2 = new Intent(contextWrapper, SUTAgentAndroid.class); PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent2, 0); notification.setLatestEventInfo(context, tickerText, expandedText, launchIntent); notificationManager.notify(1959, notification); }
From source file:com.guardtrax.ui.screens.HomeScreen.java
@Override public void onResume() { //if exiting from the scan screen with an unregistered app if (GTConstants.exitingScanScreen && !Utility.deviceRegistered()) onBackPressed();// w w w. j a v a 2 s . c om //if this is a newly registered app then reboot if (newRegistration && Utility.deviceRegistered()) { try { Intent restartIntent = getPackageManager().getLaunchIntentForPackage(getPackageName()); PendingIntent intent = PendingIntent.getActivity(HomeScreen.this, 0, restartIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); manager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, intent); System.exit(2); } catch (Exception e) { Toast.makeText(getApplicationContext(), "ON RESUME ERROR: " + e, Toast.LENGTH_LONG).show(); } } else { if (!ScreenReceiver.wasScreenOn) { //Toast.makeText(getApplicationContext(), "ON RESUME", Toast.LENGTH_LONG).show(); //if(ftpDownload.getStatus() != AsyncTask.Status.RUNNING)syncFTP(); //syncFTP(); } syncFTP(); setuserBanner(); //if returning from tag scan for time and attendance after an end shift then taa was set to 1 //set taa to 2 and then launch dialog to display the time and attendance record and then signature page if (taa == 1) { taa = 0; } if (taa == 2) { //write to tar, transfer file to send directory Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.tarfileName, "End shift;" + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n", true); //write additional info to tar file Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.tarfileName, "Total Time;" + Utility.gettimeDiff(Utility.getsessionStart(), Utility.getLocalDateTime()) + "\r\n" + "Time on Lunch;" + lunchTime + "\r\n" + "Time on Break;" + breakTime + "\r\n", true); //give time for file write Utility.initializeGeneralTimer(2000); do { Utility.Sleep(100); } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag()); lunchTime = "00:00:00:00"; breakTime = "00:00:00:00"; taa = 5; show_taaSignature_dialog(); //returning from end shift location scan } if (taa == 3) { //write the event 25 information to the file String GM = ""; if (GTConstants.isSignature) { GM = Utility.getHeaderMessage("$GM") + ",25," + getCellID() + CRLF + "***SIGNATURE***" + CRLF + Utility.getsharedPreference(HomeScreen.this, "signaturefileName"); GTConstants.isSignature = false; signaturefileName = ""; } else GM = Utility.getHeaderMessage("$GM") + ",25," + getCellID(); Utility.write_to_file(HomeScreen.this, GTConstants.dardestinationFolder + GTConstants.tarfileName, GM + "\r\n", true); //give time for file write Utility.initializeGeneralTimer(2000); do { Utility.Sleep(100); } while (!Utility.fileAccessComplete() && !Utility.getgeneraltimerFlag()); //move the tar file to the send file folder File from = new File(GTConstants.dardestinationFolder, GTConstants.tarfileName); //change the file name to match the $GM time and date String[] parse = GM.split(","); String newFile = GTConstants.LICENSE_ID.substring(7) + "_" + parse[10] + "_" + parse[2] + "_tar.tar"; File to = new File(GTConstants.sendfileFolder, newFile); from.renameTo(to); endshiftCode(); taa = 0; } //check if the tag is in a tour if (GTConstants.exitingScanScreen) { if (GTConstants.isTour) { if (GTConstants.tourName.length() == 1) { if (getlasttagScanned().length() == 16) show_tours_dialog(true); } else { updateTour(getlasttagScanned()); } } //check if this is an account setup tag, designated by an "@&" as the first two characters if (getlasttagScanned().length() == 16) { String temp = Utility.get_from_GTParamsDataBase(HomeScreen.this, getlasttagScanned()); if (temp.contains("@&")) { temp = temp.substring(2); setupAccounts("0", temp); //Toast.makeText(getApplicationContext(), temp, Toast.LENGTH_LONG).show(); } } GTConstants.exitingScanScreen = false; } } super.onResume(); }
From source file:com.ubuntuone.android.files.service.UpDownService.java
public void notifyRoamingSoAutoUploadDisabled() { final String title = "Roaming, Auto Upload disabled"; final String text = "To enable, change your settings."; Notification notification = new NotificationCompat.Builder(this).setOngoing(false) .setTicker("Roaming, Auto Upload disabled").setSmallIcon(R.drawable.stat_sys_upload_anim0) .setOnlyAlertOnce(true).setAutoCancel(true).getNotification(); final Intent intent = new Intent(UpDownService.this, PreferencesActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(PreferencesActivity.AUTOUPLOAD_SCREEN, 1); final PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), REQUEST_AUTOUPLOAD_SCREEN, intent, 0);//from w ww . j a va 2s .co m notification.setLatestEventInfo(UpDownService.this, title, text, pi); notificationManager.notify(R.id.stat_roaming_autoupload_off_id, notification); }
From source file:edu.mit.mobile.android.locast.net.NetworkClient.java
/** * Uploads the content, displaying a notification in the system tray. The notification will show * a progress bar as the upload goes on and will show a message when finished indicating whether * or not it was successful.//w w w . j a va2 s . c o m * * @param context * @param cast * cast item * @param serverPath * the path on which * @param localFile * @param contentType * @param uploadType * @throws NetworkProtocolException * @throws IOException * @throws JSONException */ public JSONObject uploadContentWithNotification(Context context, Uri cast, String serverPath, Uri localFile, String contentType, UploadType uploadType) throws NetworkProtocolException, IOException, JSONException { String castTitle = Cast.getTitle(context, cast); if (castTitle == null) { castTitle = "untitled (cast #" + cast.getLastPathSegment() + ")"; } JSONObject updatedCastMedia; final ProgressNotification notification = new ProgressNotification(context, context.getString(R.string.sync_uploading_cast, castTitle), ProgressNotification.TYPE_UPLOAD, PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, cast).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0), true); // assume fail: when successful, all will be reset. notification.successful = false; notification.doneTitle = context.getString(R.string.sync_upload_fail); notification.doneText = context.getString(R.string.sync_upload_fail_message, castTitle); notification.doneIntent = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, cast).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0); final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationProgressListener tpl = new NotificationProgressListener(nm, notification, 0, (int) ContentUris.parseId(cast)); try { final AssetFileDescriptor afd = context.getContentResolver().openAssetFileDescriptor(localFile, "r"); final long max = afd.getLength(); tpl.setSize(max); switch (uploadType) { case RAW_PUT: updatedCastMedia = uploadContent(context, tpl, serverPath, localFile, contentType); break; case FORM_POST: updatedCastMedia = uploadContentUsingForm(context, tpl, serverPath, localFile, contentType); break; default: throw new IllegalArgumentException("unhandled upload type: " + uploadType); } notification.doneTitle = context.getString(R.string.sync_upload_success); notification.doneText = context.getString(R.string.sync_upload_success_message, castTitle); notification.successful = true; } catch (final NetworkProtocolException e) { notification.setUnsuccessful(e.getLocalizedMessage()); throw e; } catch (final IOException e) { notification.setUnsuccessful(e.getLocalizedMessage()); throw e; } finally { tpl.done(); } return updatedCastMedia; }