Tabnine Logo
Context.getSystemService
Code IndexAdd Tabnine to your IDE (free)

How to use
getSystemService
method
in
android.content.Context

Best Java code snippets using android.content.Context.getSystemService (Showing top 20 results out of 19,431)

Refine searchRefine arrow

  • LayoutInflater.inflate
  • View.findViewById
  • ConnectivityManager.getActiveNetworkInfo
  • NetworkInfo.isConnected
  • TextView.setText
  • View.getTag
  • View.setTag
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;
}
android.contentContextgetSystemService

Popular methods of Context

  • getPackageName
  • getResources
  • obtainStyledAttributes
  • getApplicationContext
  • getString
  • getPackageManager
  • startActivity
  • getContentResolver
  • getSharedPreferences
  • getAssets
  • getTheme
  • getCacheDir
  • getTheme,
  • getCacheDir,
  • startService,
  • sendBroadcast,
  • getFilesDir,
  • registerReceiver,
  • getApplicationInfo,
  • unregisterReceiver,
  • getExternalCacheDir

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • getContentResolver (Context)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • JComboBox (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • Runner (org.openjdk.jmh.runner)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now