Java Code Examples for android.content.Context#getSystemService()

The following examples show how to use android.content.Context#getSystemService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LeanplumNotificationChannel.java    From Leanplum-Android-SDK with Apache License 2.0 6 votes vote down vote up
/**
 * Delete push notification channel group.
 *
 * @param context The application context.
 * @param groupId The id of the channel.
 */
private static void deleteNotificationGroup(Context context, String groupId) {
  if (context == null || TextUtils.isEmpty(groupId)) {
    return;
  }
  if (BuildUtil.isNotificationChannelSupported(context)) {
    try {
      NotificationManager notificationManager =
          (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      if (notificationManager == null) {
        Log.e("Notification manager is null");
        return;
      }

      notificationManager.deleteNotificationChannelGroup(groupId);
    } catch (Throwable t) {
      Util.handleException(t);
    }
  }
}
 
Example 2
Source File: ImageUtils.java    From TVSample with Apache License 2.0 6 votes vote down vote up
public static int getScreenHeightPixels(Context mContext) {
    WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int height = size.y;
    return height;
}
 
Example 3
Source File: AudioSlidePlayer.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
private AudioSlidePlayer(@NonNull Context context,
                         @Nullable
                         MasterSecret masterSecret,
                         @NonNull AudioSlide slide,
                         @NonNull Listener listener) {
    this.context = context;
    this.masterSecret = masterSecret;
    this.slide = slide;
    this.listener = new WeakReference<>(listener);
    this.progressEventHandler = new ProgressEventHandler(this);
    this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    this.sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    this.proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

    if (Build.VERSION.SDK_INT >= 21) {
        this.wakeLock = AppUtil.INSTANCE.getPowerManager(context).newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, TAG);
    } else {
        this.wakeLock = null;
    }
}
 
Example 4
Source File: UserInfo.java    From echo with GNU General Public License v3.0 5 votes vote down vote up
public static String getUserCountryCode(Context c) {

        final TelephonyManager manager = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE);
        //getNetworkCountryIso
        final String countryLetterCode = manager.getSimCountryIso().toUpperCase();
        String[] rl = c.getResources().getStringArray(R.array.country_codes);
        for (String aRl : rl) {
            String[] g = aRl.split(",");
            if (g[1].trim().equals(countryLetterCode.trim())) {
                return g[0];
            }
        }
        return "";
    }
 
Example 5
Source File: ViewUtils.java    From VideoMeeting with Apache License 2.0 5 votes vote down vote up
/**
 * Uses given views to hide soft keyboard and to clear current focus.
 * 
 * @param context
 *            Context
 * @param views
 *            Currently focused views
 */
public static void hideSoftKeyboard(Context context, View... views) {
	if (views == null)
		return;
	InputMethodManager manager = (InputMethodManager) context
			.getSystemService(Context.INPUT_METHOD_SERVICE);
	for (View currentView : views) {
		if (null == currentView)
			continue;
		manager.hideSoftInputFromWindow(currentView.getWindowToken(), 0);
		currentView.clearFocus();
	}
}
 
Example 6
Source File: NetworkUtils.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"MissingPermission"})
public static boolean isMobileConnected(Context context) {
    if (context != null) {
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = manager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            return networkInfo.isAvailable();
        }
    }
    return false;
}
 
Example 7
Source File: NotificationChannel.java    From Shipr-Community-Android with GNU General Public License v3.0 5 votes vote down vote up
public NotificationChannel(Context context, DatabaseReference reference, String channel_Id, int channel_no) {
    this.context = context;
    this.channel_Id = channel_Id;
    this.reference = reference.child(channel_Id);
    String channel_Key = context.getString(R.string.shared_preference_key) + channel_Id;
    sharedPreferences = context.getSharedPreferences(channel_Key, Context.MODE_PRIVATE);
    count = sharedPreferences.getInt("count", 0);
    id = channel_no;
    messages = new ArrayList<>();
    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}
 
Example 8
Source File: EndlessTaggingActivity.java    From Android-SDK with MIT License 4 votes vote down vote up
public PointsAdapter( Context context )
{
  inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
}
 
Example 9
Source File: NotificationBroadcastReceiver.java    From open with GNU General Public License v3.0 4 votes vote down vote up
private void cancelAllNotifications(Context context) {
    final NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Activity.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}
 
Example 10
Source File: NetworkUtils.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
static public NetworkInfo getConnectedNetworkInfo(Context context) {

        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) {
            return networkInfo;
        }

        networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

        networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

        networkInfo = connectivityManager.getNetworkInfo(CONNECTIVITY_TYPE_WIMAX);
        if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

        networkInfo = connectivityManager.getNetworkInfo(CONNECTIVITY_TYPE_ETHERNET);
        if (networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) return networkInfo;

        log.info("Could not find any connected network...");

        return null;
    }
 
Example 11
Source File: Util.java    From dynamiclistview with MIT License 4 votes vote down vote up
public static int getScreenHeight(Context context) {
	WindowManager display = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	return display.getDefaultDisplay().getHeight();
}
 
Example 12
Source File: ServiceUtil.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
public static TelephonyManager getTelephonyManager(Context context) {
  return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
}
 
Example 13
Source File: NetworkManagerFinal.java    From zone-sdk with MIT License 4 votes vote down vote up
/**
 * 获取ConnectivityManager
 */
public static ConnectivityManager getConnectivityManager(Context context) {
    return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
 
Example 14
Source File: OrientationMonitor.java    From talkback with Apache License 2.0 4 votes vote down vote up
public OrientationMonitor(Compositor compositor, Context context) {
  this.compositor = compositor;
  powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  listeners = new ArrayList<>();
}
 
Example 15
Source File: TestFragment.java    From v2ex with Apache License 2.0 4 votes vote down vote up
@Override
public View newCollectionItemView(Context context, int groupId, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    return inflater.inflate(R.layout.item_image, parent, false);
}
 
Example 16
Source File: TimelinePostsSyncService.java    From aptoide-client with GNU General Public License v2.0 4 votes vote down vote up
public void sync(Context context, String packageName) {
    try {
        Log.d("AptoideTimeline", "Starting timelinePostsService");
        SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(Aptoide.getContext());
        if(sPref.contains("timelineTimestamp") && sPref.getBoolean("socialtimelinenotifications", true)) {


            TimelineActivityJson timelineActivityJson = TimelineCheckRequestSync.getRequest("new_installs");

            Intent intent = new Intent(context, MainActivity.class);
            intent.putExtra("fromTimeline", true);

            intent.setClassName(packageName, MainActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setAction(Intent.ACTION_VIEW);

            PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);


            Notification notification = new NotificationCompat.Builder(context)
                    .setSmallIcon(R.drawable.ic_stat_aptoide_fb_notification)
                    .setContentIntent(resultPendingIntent)
                    .setOngoing(false)
                    .setAutoCancel(true)
                    .setContentTitle(context.getString(R.string.notification_timeline_posts))
                    .setContentText(context.getString(R.string.notification_social_timeline)).build();
            notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
            ArrayList<String> avatarLinks = new ArrayList<String>();

            try {

                setAvatares(avatarLinks, timelineActivityJson.getNew_installs().getFriends());

                if (Build.VERSION.SDK_INT >= 16) {
                    RemoteViews expandedView = new RemoteViews(context.getPackageName(), R.layout.push_notification_timeline_activity);
                    expandedView.setTextViewText(R.id.description, context.getString(R.string.notification_timeline_posts));
                    expandedView.removeAllViews(R.id.linearLayout2);
                    for (String avatar : avatarLinks) {
                        Bitmap loadedImage = ImageLoader.getInstance().loadImageSync(avatar);
                        RemoteViews imageView = new RemoteViews(context.getPackageName(), R.layout.timeline_friend_iv);
                        imageView.setImageViewBitmap(R.id.friend_avatar, loadedImage);
                        expandedView.addView(R.id.linearLayout2, imageView);
                    }

                    notification.bigContentView = expandedView;
                }


                if (!avatarLinks.isEmpty()) {
                    final NotificationManager managerNotification = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                    managerNotification.notify(86459, notification);
                }


            } catch (NullPointerException ignored) {
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 17
Source File: Fingerprint.java    From px-android with MIT License 4 votes vote down vote up
public static String getDeviceResolution(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();

    return display.getWidth() + "x" + display.getHeight();
}
 
Example 18
Source File: ResourceCursorAdapter.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor the enables auto-requery.
 *
 * @deprecated This option is discouraged, as it results in Cursor queries
 * being performed on the application's UI thread and thus can cause poor
 * responsiveness or even Application Not Responding errors.  As an alternative,
 * use {@link android.app.LoaderManager} with a {@link android.content.CursorLoader}.
 *
 * @param context The context where the ListView associated with this adapter is running
 * @param layout resource identifier of a layout file that defines the views
 *            for this list item.  Unless you override them later, this will
 *            define both the item views and the drop down views.
 */
@Deprecated
public ResourceCursorAdapter(Context context, int layout, Cursor c) {
    super(context, c);
    mLayout = mDropDownLayout = layout;
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mDropDownInflater = mInflater;
}
 
Example 19
Source File: WhitelistFragment.java    From DeviceConnect-Android with MIT License 2 votes vote down vote up
/**
 * Constructor.
 * 
 * @param context Context
 * @param list The list of book-marks
 */
ApplicationListAdapter(final Context context, final List<KnownApplicationInfo> list) {
    super(context, 0, list);
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mList = list;
}
 
Example 20
Source File: VibrateUtil.java    From AndroidBase with Apache License 2.0 2 votes vote down vote up
/**
 * Vibrate with a given pattern.
 * <p/>
 * <p>
 * Pass in an array of ints that are the durations for which to turn on or off
 * the vibrator in milliseconds.  The first value indicates the number of milliseconds
 * to wait before turning the vibrator on.  The next value indicates the number of milliseconds
 * for which to keep the vibrator on before turning it off.  Subsequent values alternate
 * between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
 * </p><p>
 * To cause the pattern to repeat, pass the index into the pattern array at which
 * to start the repeat, or -1 to disable repeating.
 * </p>
 * <p>This method requires the caller to hold the permission
 * {@link android.Manifest.permission#VIBRATE}.
 *
 * @param pattern an array of longs of times for which to turn the vibrator on or off.
 * @param repeat  the index into pattern at which to repeat, or -1 if
 *                you don't want to repeat.
 */
public static void vibrate(Context context, long[] pattern, int repeat) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(pattern, repeat);
}