android.content.Context.getSystemService()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(246)

本文整理了Java中android.content.Context.getSystemService()方法的一些代码示例,展示了Context.getSystemService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.getSystemService()方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:getSystemService

Context.getSystemService介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

public boolean isOnline(Context context) {

  ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo netInfo = cm.getActiveNetworkInfo();
  //should check null because in airplane mode it will be null
  return (netInfo != null && netInfo.isConnected());
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

/**
 * 获取活动网路信息
 *
 * @param context 上下文
 * @return NetworkInfo
 */
private static NetworkInfo getActiveNetworkInfo(Context context) {
  ConnectivityManager cm = (ConnectivityManager) context
      .getSystemService(Context.CONNECTIVITY_SERVICE);
  return cm.getActiveNetworkInfo();
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

static View inflate(Context applicationContext, int layoutId) {
  LayoutInflater inflate = (LayoutInflater) applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  return inflate.inflate(layoutId, null);
}

代码示例来源:origin: stackoverflow.com

super(context, resource, textViewResourceId, objects);
mResourceId = resource;
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  view = mLayoutInflater.inflate(mResourceId, parent, false);
  holder = new ViewHolder();
  holder.name = (TextView)view.findViewById(R.id.text);
  holder.radioBtn = (RadioButton)view.findViewById(R.id.radioButton1);
  view.setTag(holder);
}else{
  holder = (ViewHolder)view.getTag();

代码示例来源:origin: stackoverflow.com

AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater)
    mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
    (ViewGroup) findViewById(R.id.layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();

代码示例来源:origin: novoda/android-demos

public View getView(int position, View convertView, ViewGroup parent) {
    View view;
    if (convertView == null) {
      final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
          Context.LAYOUT_INFLATER_SERVICE);
      view = inflater.inflate(R.layout.carousel_gallery_li, null);
    } else {
      view = convertView;
    }

    final ImageView imageView = (ImageView) view.findViewById(R.id.image);

    Bitmap image = null;
    try {
      InputStream bitmap = mContext.getAssets().open(PLACEHOLDER_FILE);
      image = BitmapFactory.decodeStream(bitmap);
    } catch (IOException exception) {
      Log.e(TAG, "An error occurred when you have tried to open the file: "+ PLACEHOLDER_FILE, exception);
    }

    imageView.setImageBitmap(image);
    return view;
  }
}

代码示例来源:origin: joyoyao/superCleanMaster

@SuppressLint("NewApi")
public RoundCornerProgressBar(Context context, AttributeSet attrs) {
  super(context, attrs);
  if (!isInEditMode()) {
    isProgressBarCreated = false;
    isProgressSetBeforeDraw = false;
    isMaxProgressSetBeforeDraw = false;
    isBackgroundColorSetBeforeDraw = false;
    isProgressColorSetBeforeDraw = false;
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.round_corner_layout, this);
    setup(context, attrs);
    isProgressBarCreated = true;
  } else {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      setBackground(new ColorDrawable(Color.parseColor("#CCCCCC")));
    } else {
      setBackgroundColor(Color.parseColor("#CCCCCC"));
    }
    setGravity(Gravity.CENTER);
    
    TextView tv = new TextView(context);
    tv.setText("RoundCornerProgressBar");
    addView(tv);
  }
}

代码示例来源:origin: JohnPersano/SuperToasts

/**
 * Protected constructor that is overridden by the SuperActivityToast class.         
 */
protected SuperToast(@NonNull Context context,  @NonNull Style style, @Style.Type int type) {
  this.mContext = context;
  this.mStyle = style;
  this.mStyle.type = type;
  final LayoutInflater layoutInflater = (LayoutInflater) context
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  this.mView = onCreateView(context, layoutInflater, type);
  this.mTextView = (TextView) this.mView.findViewById(R.id.message);
}

代码示例来源:origin: evernote/android-job

@Test
public void testNetworkStateUnmeteredWifi() {
  NetworkInfo networkInfo = mock(NetworkInfo.class);
  when(networkInfo.isConnected()).thenReturn(true);
  when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
  when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_WIFI);
  ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
  when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
  Context context = mock(MockContext.class);
  when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
  assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.UNMETERED);
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

public static boolean isWifiConnected(Context context) {
  ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
  if (wifiNetworkInfo.isConnected()) {
    return true;
  }
  return false;
}

代码示例来源:origin: android10/Android-CleanArchitecture

/**
  * Checks if the device has any active internet connection.
  *
  * @return true device with internet connection, otherwise false.
  */
 private boolean isThereInternetConnection() {
  boolean isConnected;

  ConnectivityManager connectivityManager =
    (ConnectivityManager) this.context.getSystemService(Context.CONNECTIVITY_SERVICE);
  NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
  isConnected = (networkInfo != null && networkInfo.isConnectedOrConnecting());

  return isConnected;
 }
}

代码示例来源:origin: androidquery/androidquery

Integer layout = (Integer) convertView.getTag(AQuery.TAG_LAYOUT);
  if(layout != null && layout.intValue() == layoutId){
    return convertView;
  inflater = act.getLayoutInflater();
}else{
  inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(layoutId, root, false);	
view.setTag(AQuery.TAG_LAYOUT, layoutId);

代码示例来源:origin: stackoverflow.com

AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
                (ViewGroup) findViewById(R.id.layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();

代码示例来源:origin: cymcsg/UltimateAndroid

private void initView() {
  LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View view = inflater.inflate(R.layout.ultimate_listview_layout, this);
  mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.ultimate_listview_swipe_layout);
  mBasicUltimateListView = (BasicUltimateListView) view.findViewById(R.id.basicUltimateListView);
  mSwipeRefreshLayout.setEnabled(false);
  mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
      android.R.color.holo_green_light,
      android.R.color.holo_orange_light,
      android.R.color.holo_red_light);
}

代码示例来源:origin: aporter/coursera-android

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
  LayoutInflater inflater = (LayoutInflater) context
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  //noinspection ConstantConditions
  return inflater.inflate(R.layout.list_item, parent, false);
}

代码示例来源:origin: joyoyao/superCleanMaster

isProgressColorSetBeforeDraw = false;
isHeaderColorSetBeforeDraw = false;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.round_corner_with_icon_layout, this);
setup(context, attrs);
isProgressBarCreated = true;
tv.setText("IconRoundCornerProgressBar");
addView(tv);

代码示例来源:origin: JohnPersano/SuperToasts

/**
 * Public constructor for a SuperToast.
 *
 * @param context A valid Context
 * @param style The desired Style             
 */
public SuperToast(@NonNull Context context, @NonNull Style style) {
  this.mContext = context;
  this.mStyle = style;
  final LayoutInflater layoutInflater = (LayoutInflater) context
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  this.mView = onCreateView(context, layoutInflater, this.mStyle.type);
  this.mTextView = (TextView) this.mView.findViewById(R.id.message);
}

代码示例来源:origin: kaushikgopal/RxJava-Android-Samples

private boolean getConnectivityStatus(Context context) {
 ConnectivityManager cm =
   (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
 NetworkInfo networkInfo = cm.getActiveNetworkInfo();
 return networkInfo != null && networkInfo.isConnected();
}

代码示例来源:origin: evernote/android-job

@Test
public void testNetworkStateVpn() {
  NetworkInfo networkInfo = mock(NetworkInfo.class);
  when(networkInfo.isConnected()).thenReturn(true);
  when(networkInfo.isConnectedOrConnecting()).thenReturn(true);
  when(networkInfo.getType()).thenReturn(ConnectivityManager.TYPE_VPN);
  ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
  when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
  Context context = mock(MockContext.class);
  when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
  assertThat(Device.getNetworkType(context)).isEqualTo(JobRequest.NetworkType.NOT_ROAMING);
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

/**
 * 判断wifi是否连接状态
 * <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
 *
 * @param context 上下文
 * @return true: 连接<br>false: 未连接
 */
public static boolean isWifiConnected(Context context) {
  ConnectivityManager cm = (ConnectivityManager) context
      .getSystemService(Context.CONNECTIVITY_SERVICE);
  return cm != null && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
}

相关文章

Context类方法