List of usage examples for android.app Activity getSystemService
@Override
public Object getSystemService(@ServiceName @NonNull String name)
From source file:org.nla.tarotdroid.lib.helpers.FacebookHelper.java
/** * Shows a notification indicating the publish is in progress. * @param activity//from ww w .j a va 2 s. c o m * @return */ public static int showNotificationStartProgress(Activity activity) { checkArgument(activity != null, "activity is null"); int notificationId = RANDOM.nextInt(); try { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.icon_notification_small) .setContentTitle(AppContext.getApplication().getResources() .getString(R.string.titleFacebookNotificationInProgress)) .setContentText(AppContext.getApplication().getResources() .getString(R.string.msgFacebookNotificationInProgress)) .setProgress(0, 0, true); NotificationManager mNotificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(notificationId, mBuilder.build()); } // Problem with older versions of android or devices, need to provide a PendingIntent that leads to an activity catch (IllegalArgumentException iae) { Intent intent = new Intent(activity, NotificationActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.icon_notification_small) .setContentTitle(AppContext.getApplication().getResources() .getString(R.string.titleFacebookNotificationInProgress)) .setContentText(AppContext.getApplication().getResources() .getString(R.string.msgFacebookNotificationInProgress)) .setProgress(0, 0, true).setContentIntent(contentIntent); NotificationManager mNotificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(notificationId, mBuilder.build()); } return notificationId; }
From source file:com.github.rutvijkumar.twittfuse.Util.java
public static final void scheduleAlarm(Activity activity) { // Construct an intent that will execute the AlarmReceiver Intent intent = new Intent(activity.getApplicationContext(), OfflineTweetAlarmReceiver.class); // Create a PendingIntent to be triggered when the alarm goes off final PendingIntent pIntent = PendingIntent.getBroadcast(activity, OfflineTweetAlarmReceiver.REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Setup periodic alarm every 10 seconds long firstMillis = System.currentTimeMillis(); // first run of alarm is // immediate/*w w w . ja va 2s. c o m*/ int intervalMillis = 10000; // 10 seconds AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, intervalMillis, pIntent); }
From source file:org.braiden.fpm2.PasswordItemListActivity.java
public static void copyItemProperty(Activity activity, long id, String property) { FpmApplication app = (FpmApplication) activity.getApplication(); PasswordItem item = app.getPasswordItemById(id); if (item != null) { try {// ww w. j av a 2 s.co m String value = (String) PropertyUtils.getProperty(item, property); if (FpmCrypt.PROPERTY_PASSWORD.equals(property)) { value = app.decrypt(value); } ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(CLIPBOARD_SERVICE); clipboard.setText(value); } catch (Exception e) { Log.w(TAG, "Failed to access property \"" + property + "\" of item id " + id + ".", e); } } }
From source file:org.nla.tarotdroid.lib.helpers.FacebookHelper.java
/** * Shows a notification indicating the publish is finished. * @param activity//from ww w . jav a 2 s .c o m * @param url * @param notificationId */ public static void showNotificationStopProgressSuccess(Activity activity, String url, int notificationId) { checkArgument(activity != null, "activity is null"); checkArgument(activity != null, "url is null"); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.icon_notification_small) .setContentTitle(AppContext.getApplication().getResources() .getString(R.string.titleFacebookNotificationDone)) .setContentText( AppContext.getApplication().getResources().getString(R.string.msgFacebookNotificationDone)) .setAutoCancel(true).setProgress(0, 0, false); mBuilder.setContentIntent(PendingIntent.getActivity(activity, 0, intent, 0)); NotificationManager mNotificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(notificationId, mBuilder.build()); }
From source file:org.chromium.ChromeSystemMemory.java
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); Activity activity = cordova.getActivity(); activityManager = (ActivityManager) activity.getSystemService(Activity.ACTIVITY_SERVICE); }
From source file:com.upnext.blekit.BLEKit.java
/** * Checks whether Bluetooth LE is available on the device and Bluetooth turned on. * * If BLE is not supported, then a dialog with appropriate message is shown. * If BLE is supported, but Bluetooth is not turned on then a dialog with message is shown and an option to go directly to settings and turn Bluetooth on. * * A good place to invoke this method would be onResume() in your Activity. * * @param activity Activity//from w ww . j a v a 2s .c om * @return false if BLE is not supported or Bluetooth not turned on; otherwise true */ public static boolean checkAvailability(Activity activity) { if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { showErrorDialog(activity.getString(R.string.blekit_ble_unsupported), activity, true); } else { if (((BluetoothManager) activity.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter() .isEnabled()) { return true; } showErrorDialog(activity.getString(R.string.blekit_bt_not_on), activity, false); } return false; }
From source file:com.jetheis.android.makeitrain.fragment.AboutDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder;/* ww w .ja v a 2 s .c o m*/ Activity activity = getActivity(); LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.about_dialog_fragment, null); TextView text = (TextView) layout.findViewById(R.id.about_dialog_fragment_text_view); text.setText(R.string.about_text); builder = new AlertDialog.Builder(activity); builder.setView(layout); builder.setTitle(R.string.about_make_it_rain); builder.setPositiveButton(R.string.cool_thanks, null); return builder.create(); }
From source file:org.nla.tarotdroid.lib.helpers.FacebookHelper.java
/** * Shows a notification indicating the publish has failed. * @param activity//from w w w . j a v a 2s .c om * @param notificationId */ public static void showNotificationStopProgressFailure(Activity activity, int notificationId) { checkArgument(activity != null, "activity is null"); Intent intent = new Intent(activity, NotificationActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(activity) .setSmallIcon(R.drawable.icon_notification_small) .setContentTitle(AppContext.getApplication().getResources() .getString(R.string.titleFacebookNotificationError)) .setContentText( AppContext.getApplication().getResources().getString(R.string.msgFacebookNotificationError)) .setAutoCancel(true).setProgress(0, 0, false).setContentIntent(contentIntent); NotificationManager mNotificationManager = (NotificationManager) activity .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(notificationId, mBuilder.build()); AppContext.getApplication().getNotificationIds().clear(); }
From source file:org.badreader.client.fragments.BaseFragment.java
protected void hideKeyboard(Activity _activity) { try {/* ww w . j a v a 2 s . c o m*/ InputMethodManager imm = (InputMethodManager) _activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(_activity.getCurrentFocus().getWindowToken(), 0); } } catch (Exception e) { e.printStackTrace(); } }
From source file:eu.intermodalics.tango_ros_streamer.ImuNode.java
public ImuNode(Activity activity) { mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE); mRotationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); mGyroscopeSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mAccelerometerSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); }