List of usage examples for android.app PendingIntent getBroadcast
public static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, @Flags int flags)
From source file:dk.ciid.android.infobooth.activities.IntroductionActivity.java
@Override public void onCreate(Bundle savedInstanceState) { /* Variables received through Intent */ Intent openActivity = getIntent(); // this is just for example purpose isInDebugMode = openActivity.getBooleanExtra("isInDebugMode", true); // should the app send a welcome sms after subscribing? voice1 = openActivity.getStringExtra("voice1"); // path to voice file 1 voice2 = openActivity.getStringExtra("voice2"); // path to voice file 2 voice3 = openActivity.getStringExtra("voice3"); // path to voice file 3 voice4 = openActivity.getStringExtra("voice4"); // path to voice file 4 voice5 = openActivity.getStringExtra("voice5"); // path to voice file 5 voice6 = openActivity.getStringExtra("voice6"); // path to voice file 6 /* Variables received through Intent */ super.onCreate(savedInstanceState); /* ARDUINO COMMUNICATION STUFF ********************************************/ // a reference to the USB system service is obtained so that you can call its methods later on mUsbManager = UsbManager.getInstance(this); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, filter); if (getLastNonConfigurationInstance() != null) { mAccessory = (UsbAccessory) getLastNonConfigurationInstance(); openAccessory(mAccessory);//from w w w. ja va 2 s . c o m } /* ARDUINO COMMUNICATION STUFF ********************************************/ gestureScanner = new GestureDetector(this); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_introduction); // Set up sound playback initMediaPlayer(); runOnUiThread(new Runnable() { public void run() { if (isInDebugMode) Toast.makeText(getApplicationContext(), "Debug mode is ON", Toast.LENGTH_SHORT).show(); } }); }
From source file:com.keepassdroid.EntryActivity.java
private Notification getNotification(String intentText, int descResId) { String desc = getString(descResId); Intent intent = new Intent(intentText); PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // no longer supported for api level >22 // notify.setLatestEventInfo(this, getString(R.string.app_name), desc, pending); // so instead using compat builder and create new notification NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtil.COPY_CHANNEL_ID); Notification notify = builder.setContentIntent(pending).setContentText(desc) .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.drawable.notify).setTicker(desc) .setWhen(System.currentTimeMillis()).build(); return notify; }
From source file:net.kourlas.voipms_sms.Notifications.java
public void showNotifications(List<String> contacts) { if (!(ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationsActivity)) { Conversation[] conversations = Database.getInstance(applicationContext) .getConversations(preferences.getDid()); for (Conversation conversation : conversations) { if (!conversation.isUnread() || !contacts.contains(conversation.getContact()) || (ActivityMonitor.getInstance().getCurrentActivity() instanceof ConversationActivity && ((ConversationActivity) ActivityMonitor.getInstance().getCurrentActivity()) .getContact().equals(conversation.getContact()))) { continue; }//from w ww .j a va 2 s . co m String smsContact = Utils.getContactName(applicationContext, conversation.getContact()); if (smsContact == null) { smsContact = Utils.getFormattedPhoneNumber(conversation.getContact()); } String allSmses = ""; String mostRecentSms = ""; boolean initial = true; for (Message message : conversation.getMessages()) { if (message.getType() == Message.Type.INCOMING && message.isUnread()) { if (initial) { allSmses = message.getText(); mostRecentSms = message.getText(); initial = false; } else { allSmses = message.getText() + "\n" + allSmses; } } else { break; } } NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(applicationContext); notificationBuilder.setContentTitle(smsContact); notificationBuilder.setContentText(mostRecentSms); notificationBuilder.setSmallIcon(R.drawable.ic_chat_white_24dp); notificationBuilder.setPriority(Notification.PRIORITY_HIGH); notificationBuilder .setSound(Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound())); notificationBuilder.setLights(0xFFAA0000, 1000, 5000); if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) { notificationBuilder.setVibrate(new long[] { 0, 250, 250, 250 }); } else { notificationBuilder.setVibrate(new long[] { 0 }); } notificationBuilder.setColor(0xFFAA0000); notificationBuilder.setAutoCancel(true); notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(allSmses)); Bitmap largeIconBitmap; try { largeIconBitmap = MediaStore.Images.Media.getBitmap(applicationContext.getContentResolver(), Uri.parse(Utils.getContactPhotoUri(applicationContext, conversation.getContact()))); largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false); largeIconBitmap = Utils.applyCircularMask(largeIconBitmap); notificationBuilder.setLargeIcon(largeIconBitmap); } catch (Exception ignored) { } Intent intent = new Intent(applicationContext, ConversationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext); stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addNextIntent(intent); notificationBuilder .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT)); Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } else { //noinspection deprecation replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); } replyIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); PendingIntent replyPendingIntent = PendingIntent.getActivity(applicationContext, 0, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_24dp, applicationContext.getString(R.string.notifications_button_reply), replyPendingIntent); notificationBuilder.addAction(replyAction.build()); Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class); markAsReadIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), conversation.getContact()); PendingIntent markAsReadPendingIntent = PendingIntent.getBroadcast(applicationContext, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder markAsReadAction = new NotificationCompat.Action.Builder( R.drawable.ic_drafts_white_24dp, applicationContext.getString(R.string.notifications_button_mark_read), markAsReadPendingIntent); notificationBuilder.addAction(markAsReadAction.build()); int id; if (notificationIds.get(conversation.getContact()) != null) { id = notificationIds.get(conversation.getContact()); } else { id = notificationIdCount++; notificationIds.put(conversation.getContact(), id); } NotificationManager notificationManager = (NotificationManager) applicationContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notificationBuilder.build()); } } }
From source file:com.first.akashshrivastava.showernow.ShowerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_shower_activity); /*Launching BootReceiver to test Intent playIntent = new Intent(getApplicationContext(), BootReceiver.class); startActivity(playIntent);/*ww w . j a va 2 s .c om*/ */ //Mobile ads initialization....The long number is the AdID, can be found on AdMob - ca-app-pub-8782530512283806/2988799979 MobileAds.initialize(getApplicationContext(), "ca-app-pub-8782530512283806/2988799979"); AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); //Facebook SDK initialization... FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); shareDialog = new ShareDialog(this); mDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAuth = FirebaseAuth.getInstance(); final ImageView genderImage = (ImageView) findViewById(R.id.imageGender); guyText = (TextView) findViewById(R.id.guyText); topText = (TextView) findViewById(R.id.textView2); SharedPreferences prefs = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); extraAge = prefs.getInt("age", 0); extraFluffiness = prefs.getString("fluffiness", ""); extraGender = prefs.getString("gender", ""); extraOldTime = prefs.getLong("time", 0); extraSteps = prefs.getFloat("stepsBoot", 0); switch (extraGender) { case "male": genderImage.setImageResource(R.drawable.male_white_outline); break; case "female": genderImage.setImageResource(R.drawable.female_white_outline); break; case "other": genderImage.setImageResource(R.drawable.other_white_outline); break; } genderImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //set alarm //Swith ccase switch (event.getAction()) { case MotionEvent.ACTION_UP: // PRESSED ..PRESSED if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.female_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.female_white_outline); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.male_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.male_white_outline); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.other_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.other_white_outline); } //Resets the wave after shower..this is not getting called for some reason.... waveProgressbar.setCurrent(0, ""); guyText.setText("0 %"); waveProgressbar.setVisibility(View.INVISIBLE); topText.setText("You have showered! \n When the wave hits 100% its time for your next shower "); if (fluffiness != null && gotSteps) { Calendar cal = Calendar.getInstance(); Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class); activate.putExtra("age", age); activate.putExtra("fluffiness", fluffiness); activate.putExtra("gender", gender); activate.putExtra("steps", steps); activate.putExtra("time", System.currentTimeMillis()); AlarmManager alarms; PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate, FLAG_CANCEL_CURRENT); alarms = (AlarmManager) getSystemService(ALARM_SERVICE); alarms.cancel(alarmIntent); alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + 5000, 1000 * 60, alarmIntent);//sets the alarm mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Steps").setValue(steps);//sets old steps oldSteps = steps; mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Time").setValue(System.currentTimeMillis()); oldTime = System.currentTimeMillis(); newUser = false; SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("age", age); editor.putString("fluffiness", fluffiness); editor.putString("gender", gender); editor.putFloat("steps", steps); editor.putLong("time", System.currentTimeMillis()); editor.putFloat("stepsBoot", 0); editor.putBoolean("bootStart", true); editor.apply(); } else if (!gotSteps) { Toast.makeText(getApplicationContext(), "Waiting for steps", Toast.LENGTH_SHORT).show(); } return true; // if you want to handle the touch event case MotionEvent.ACTION_DOWN: // RELEASED..RELEASED.. if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.female_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.female_white_outline_pressed); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.male_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.male_white_outline_pressed); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.other_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.other_white_outline_pressed); } return true; // if you want to handle the touch event } //Switch case end bracket return false; } }); createWave(); setMenuColor(); setupStepcount(); setWaveHeight(); FloatingActionButton editDetails = (FloatingActionButton) findViewById(R.id.menu_item4); //edit user information. Goes to main activity editDetails.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { /* Fragment fragment = new Fragment(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(ShowerActivity.java); transaction.addToBackStack(ShowerActivity.java); transaction.commit(); */ //Fragment B at pos 2 should open when edit details is pressed.. Intent i = new Intent(ShowerActivity.this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } }); FloatingActionButton fabmenuDeleteAccount = (FloatingActionButton) findViewById(R.id.delete_Account); fabmenuDeleteAccount.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog(); } }); FloatingActionButton fabMenuItem1 = (FloatingActionButton) findViewById(R.id.menu_item); fabMenuItem1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ComponentName receiver = new ComponentName(ShowerActivity.this, AlarmReceiver.class); // alarms.cancel(alarmIntent);?? PackageManager pm = ShowerActivity.this.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); stopService(new Intent(StepCountService.STEP_COUNT_SERVICE));*/ //mFirebaseAuth.getCurrentUser().getUid() =null; SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("age", 0); editor.putString("fluffiness", ""); editor.putString("gender", ""); editor.putFloat("steps", 0); editor.putLong("time", 0); editor.putFloat("stepsBoot", 0); editor.putBoolean("bootStart", false); editor.apply(); Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate, FLAG_CANCEL_CURRENT); AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE); alarms.cancel(alarmIntent); stopService(new Intent(ShowerActivity.this, StepCountService.class)); mFirebaseAuth.getInstance().signOut(); Intent i = new Intent(ShowerActivity.this, LoginActivity.class); startActivity(i); } }); final FloatingActionButton shareButton = (FloatingActionButton) findViewById(R.id.shareButton); shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); String shareBody = "Check out this showering app at: https://play.google.com/store/apps/details?id=com.first.akashshrivastava.showernow \n"; String shareSubString = "An app that tells you when you should shower and apparently keeps you clean"; shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubString); shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(shareIntent, " Share using the following")); } }); mDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snap) { try { if ((!(mFirebaseAuth.getCurrentUser().getUid().isEmpty())) && snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("female")) { genderImage.setImageResource(R.drawable.female_white_outline); } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("male")) { genderImage.setImageResource(R.drawable.male_white_outline); } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("other")) { genderImage.setImageResource(R.drawable.other_white_outline); } } catch (Exception e) { e.printStackTrace(); } age = Integer.parseInt(snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Age").getValue().toString());//gotta get int fluffiness = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString(); gender = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString(); if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time").exists()) { oldTime = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time") .getValue(Long.class); oldSteps = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Steps") .getValue(float.class); } else { newUser = true; } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
From source file:com.jmstudios.redmoon.presenter.ScreenFilterPresenter.java
private void refreshForegroundNotification() { if (isOff()) { return;/* ww w. jav a 2 s. co m*/ } Context context = mView.getContext(); ProfilesModel profilesModel = new ProfilesModel(context); String title = context.getString(R.string.app_name); int color = context.getResources().getColor(R.color.color_primary); Intent offCommand = mFilterCommandFactory.createCommand(ScreenFilterService.COMMAND_OFF); int smallIconResId = R.drawable.notification_icon_half_moon; String contentText; int pauseOrResumeDrawableResId; Intent pauseOrResumeCommand; String pauseOrResumeActionText; if (isPaused()) { Log.d(TAG, "Creating notification while in pause state"); contentText = context.getString(R.string.paused); pauseOrResumeDrawableResId = R.drawable.ic_play; pauseOrResumeCommand = mFilterCommandFactory.createCommand(ScreenFilterService.COMMAND_ON); pauseOrResumeActionText = context.getString(R.string.resume_action); } else { Log.d(TAG, "Creating notification while NOT in pause state"); contentText = context.getString(R.string.running); pauseOrResumeDrawableResId = R.drawable.ic_pause; pauseOrResumeCommand = mFilterCommandFactory.createCommand(ScreenFilterService.COMMAND_PAUSE); pauseOrResumeActionText = context.getString(R.string.pause_action); } Intent shadesActivityIntent = new Intent(context, ShadesActivity.class); shadesActivityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pauseOrResumePI = PendingIntent.getService(context, REQUEST_CODE_ACTION_PAUSE_OR_RESUME, pauseOrResumeCommand, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent settingsPI = PendingIntent.getActivity(context, REQUEST_CODE_ACTION_SETTINGS, shadesActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent nextProfileIntent = new Intent(context, NextProfileCommandReceiver.class); PendingIntent nextProfilePI = PendingIntent.getBroadcast(context, REQUEST_CODE_NEXT_PROFILE, nextProfileIntent, 0); mNotificationBuilder = new NotificationCompat.Builder(mContext); mNotificationBuilder.setSmallIcon(smallIconResId).setContentTitle(title).setContentText(contentText) .setColor(color).setContentIntent(settingsPI) .addAction(pauseOrResumeDrawableResId, pauseOrResumeActionText, pauseOrResumePI) .addAction(R.drawable.ic_next_profile, ProfilesHelper.getProfileName(profilesModel, mSettingsModel.getProfile(), context), nextProfilePI) .setPriority(Notification.PRIORITY_MIN); if (isPaused()) { Log.d(TAG, "Creating a dismissible notification"); NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); } else { Log.d(TAG, "Creating a persistent notification"); mServiceController.startForeground(NOTIFICATION_ID, mNotificationBuilder.build()); } }
From source file:dk.ciid.android.infobooth.activities.SubscriptionFinalActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { /* Variables received through Intent */ Intent openActivity = getIntent(); // this is just for example purpose isInDebugMode = openActivity.getBooleanExtra("isInDebugMode", true); // should the app send a welcome sms after subscribing? phoneNum = openActivity.getStringExtra("phoneNum"); // get the phonenumber submitted in the last activity selectedService = openActivity.getIntExtra("selectedService", 1); // array position of selected service in last activity serviceIdItems = openActivity.getStringArrayListExtra("serviceIdItems"); // arraylist of service id's (in database) serviceNameItems = openActivity.getStringArrayListExtra("serviceNameItems"); // arraylist of service names serviceDescItems = openActivity.getStringArrayListExtra("serviceDescItems"); // arraylist of service descriptions voice1 = openActivity.getStringExtra("voice1"); // path to voice file 1 voice2 = openActivity.getStringExtra("voice2"); // path to voice file 2 voice3 = openActivity.getStringExtra("voice3"); // path to voice file 3 voice4 = openActivity.getStringExtra("voice4"); // path to voice file 4 voice5 = openActivity.getStringExtra("voice5"); // path to voice file 5 voice6 = openActivity.getStringExtra("voice6"); // path to voice file 6 /* Variables received through Intent */ // TODO Auto-generated method stub super.onCreate(savedInstanceState); /* ARDUINO COMMUNICATION STUFF ********************************************/ // a reference to the USB system service is obtained so that you can call its methods later on mUsbManager = UsbManager.getInstance(this); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, filter); if (getLastNonConfigurationInstance() != null) { mAccessory = (UsbAccessory) getLastNonConfigurationInstance(); openAccessory(mAccessory);/* w ww .ja v a2 s . co m*/ } /* ARDUINO COMMUNICATION STUFF ********************************************/ gestureScanner = new GestureDetector(this); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_subscription_final); if (!isInDebugMode) { try { //SmsManager smsManager = SmsManager.getDefault(); //smsManager.sendTextMessage(phoneNumber, null, SMSMessage, null, null); Toast.makeText(getApplicationContext(), "Thanks for subscribing!", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS failed, please try again later!", Toast.LENGTH_SHORT) .show(); e.printStackTrace(); } } else { Toast.makeText(getApplicationContext(), "Debug mode - no SMS sent to save money :)", Toast.LENGTH_SHORT) .show(); } // Set up sound playback initMediaPlayer(); }
From source file:com.google.android.apps.santatracker.SantaNotificationBuilder.java
public static void ScheduleSantaNotification(Context c, long timestamp, int notificationType) { // Only schedule a notification if the time is in the future if (timestamp < System.currentTimeMillis()) { return;/*from w w w .j ava 2s . c om*/ } AlarmManager alarm = (AlarmManager) c.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(c, NotificationBroadcastReceiver.class); i.putExtra(NotificationConstants.KEY_NOTIFICATION_ID, NotificationConstants.NOTIFICATION_ID); // Type is "takeoff", "location", etc. i.putExtra(NotificationConstants.KEY_NOTIFICATION_TYPE, notificationType); // Generate unique pending intent PendingIntent pi = PendingIntent.getBroadcast(c, notificationType, i, 0); // Deliver next time the device is woken up alarm.set(AlarmManager.RTC, timestamp, pi); }
From source file:com.gsma.rcs.ri.RcsServiceNotifManager.java
private void addImsConnectionNotification(boolean connected, String label) { Intent intent = new Intent(ACTION_VIEW_SETTINGS); PendingIntent contentIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0); String title = this.getString(R.string.notification_title_rcs_service); Notification notif = buildImsConnectionNotification(contentIntent, title, label, connected); notif.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_FOREGROUND_SERVICE; NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIF_ID, notif); }
From source file:com.google.android.gms.location.sample.locationupdatespendingintent.MainActivity.java
private PendingIntent getPendingIntent() { // Note: for apps targeting API level 25 ("Nougat") or lower, either // PendingIntent.getService() or PendingIntent.getBroadcast() may be used when requesting // location updates. For apps targeting API level O, only // PendingIntent.getBroadcast() should be used. This is due to the limits placed on services // started in the background in "O". // TODO(developer): uncomment to use PendingIntent.getService(). // Intent intent = new Intent(this, LocationUpdatesIntentService.class); // intent.setAction(LocationUpdatesIntentService.ACTION_PROCESS_UPDATES); // return PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Intent intent = new Intent(this, LocationUpdatesBroadcastReceiver.class); intent.setAction(LocationUpdatesBroadcastReceiver.ACTION_PROCESS_UPDATES); return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:no.ntnu.idi.socialhitchhiking.SocialHitchhikingApplication.java
/** * Starts a service that checks if there is a scheduled Journey in less than one hour. * It will start one minute after the app is started, then poll every ten minutes. *//*from w w w. j a v a 2 s . co m*/ public void startJourneyReminder() { Intent intent = new Intent(this, JourneyReminder.class); journeyReminder = PendingIntent.getBroadcast(this, 0, intent, 0); am.cancel(journeyReminder); int tenMinutes = 600000; am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, tenMinutes / 10, tenMinutes, journeyReminder); }