android.content.Context#getSystemService ( )源码实例Demo

下面列出了android.content.Context#getSystemService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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);
    }
  }
}
 
源代码2 项目: bcm-android   文件: AudioSlidePlayer.java
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;
    }
}
 
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);
}
 
源代码4 项目: echo   文件: UserInfo.java
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 "";
    }
 
源代码5 项目: VideoMeeting   文件: ViewUtils.java
/**
 * 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();
	}
}
 
源代码6 项目: TVSample   文件: ImageUtils.java
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;
}
 
源代码7 项目: MediaSDK   文件: NetworkUtils.java
@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;
}
 
源代码8 项目: px-android   文件: Fingerprint.java
public static String getDeviceResolution(Context context) {
    WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = manager.getDefaultDisplay();

    return display.getWidth() + "x" + display.getHeight();
}
 
源代码9 项目: aptoide-client   文件: TimelinePostsSyncService.java
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();
    }

}
 
源代码10 项目: v2ex   文件: TestFragment.java
@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);
}
 
源代码11 项目: talkback   文件: OrientationMonitor.java
public OrientationMonitor(Compositor compositor, Context context) {
  this.compositor = compositor;
  powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  listeners = new ArrayList<>();
}
 
源代码12 项目: Android-SDK   文件: EndlessTaggingActivity.java
public PointsAdapter( Context context )
{
  inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
}
 
源代码13 项目: zone-sdk   文件: NetworkManagerFinal.java
/**
 * 获取ConnectivityManager
 */
public static ConnectivityManager getConnectivityManager(Context context) {
    return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
 
源代码14 项目: Silence   文件: ServiceUtil.java
public static TelephonyManager getTelephonyManager(Context context) {
  return (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
}
 
源代码15 项目: dynamiclistview   文件: Util.java
public static int getScreenHeight(Context context) {
	WindowManager display = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
	return display.getDefaultDisplay().getHeight();
}
 
源代码16 项目: DroidDLNA   文件: NetworkUtils.java
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;
    }
 
源代码17 项目: open   文件: NotificationBroadcastReceiver.java
private void cancelAllNotifications(Context context) {
    final NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Activity.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}
 
源代码18 项目: android_9.0.0_r45   文件: ResourceCursorAdapter.java
/**
 * 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;
}
 
源代码19 项目: AndroidBase   文件: VibrateUtil.java
/**
 * 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);
}
 
源代码20 项目: DeviceConnect-Android   文件: WhitelistFragment.java
/**
 * 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;
}
 
 方法所在类
 同类方法