本文整理汇总了Java中android.content.Context.getSystemService方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getSystemService方法的具体用法?Java Context.getSystemService怎么用?Java Context.getSystemService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.getSystemService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isNetworkAvailable
import android.content.Context; //导入方法依赖的package包/类
/**
* 判断网络是否可用
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (null != connectivity) {
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (null != info && info.isConnected()) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
示例2: getView
import android.content.Context; //导入方法依赖的package包/类
@Override
public View getView(int index, View view, ViewGroup viewGroup) {
final Context context = viewGroup.getContext();
if(view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.item_power_menu, viewGroup, false);
}
PowerMenuItem powerMenuItem = (PowerMenuItem) getItem(index);
final View background = view.findViewById(R.id.item_power_menu_layout);
final TextView title = view.findViewById(R.id.item_power_menu_title);
title.setText(powerMenuItem.title);
if(powerMenuItem.isSelected) {
if(selectedMenuColor == -2)
background.setBackgroundColor(context.getResources().getColor(R.color.menu_background));
else
background.setBackgroundColor(selectedMenuColor);
if(selectedTextColor == -2)
title.setTextColor(context.getResources().getColor(R.color.menu_text_selected));
else
title.setTextColor(selectedTextColor);
} else {
if(menuColor == -2)
background.setBackgroundColor(Color.WHITE);
else
background.setBackgroundColor(menuColor);
if(textColor == -2)
title.setTextColor(context.getResources().getColor(R.color.menu_text_no_selected));
else
title.setTextColor(textColor);
}
return view;
}
示例3: refreshAttackAlarm
import android.content.Context; //导入方法依赖的package包/类
public void refreshAttackAlarm(Context context) {
if (attackDatas == null) {
return;
}
List<AttackData> copied = new ArrayList<>(attackDatas);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
for (AttackData attackData : copied) {
cancelAlarm(context, attackData);
registAttack(context, alarmManager, attackData);
}
}
示例4: isNetworkConnected
import android.content.Context; //导入方法依赖的package包/类
/**
* 判断是否有网络连接
*
* @param context
* @return
*/
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
示例5: getScreenSize
import android.content.Context; //导入方法依赖的package包/类
/**
* 获取屏幕相关参数
* @param context
* @return DisplayMetrics
*/
public static DisplayMetrics getScreenSize(Context context){
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
display.getMetrics(metrics);
return metrics;
}
示例6: isWifiEnabled
import android.content.Context; //导入方法依赖的package包/类
public static boolean isWifiEnabled(Context context) {
ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService
("connectivity");
return (mgrConn.getActiveNetworkInfo() != null && mgrConn.getActiveNetworkInfo().getState
() == State.CONNECTED) || ((TelephonyManager) context.getSystemService("phone"))
.getNetworkType() == 3;
}
示例7: isNetworkConnected
import android.content.Context; //导入方法依赖的package包/类
/**
* 判断网络是否可用
* @param context
* @param isCheckNetwork 是否检查网络,true表示检查,false表示不检查
* @return
*/
public boolean isNetworkConnected(Context context, boolean isCheckNetwork) {
if (isCheckNetwork && context != null) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
return ni != null && ni.isConnectedOrConnecting();
} else {
return true;
}
}
示例8: ConfirmDialog
import android.content.Context; //导入方法依赖的package包/类
private ConfirmDialog(Context ctx) {
mContext = ctx;
internalDialogBuilder = new AlertDialog.Builder(mContext, R.style.ConfirmDialogStyle);
layoutInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
示例9: verificaConexao
import android.content.Context; //导入方法依赖的package包/类
public static boolean verificaConexao(Context context) {
boolean conectado;
ConnectivityManager conectivtyManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
conectado = conectivtyManager.getActiveNetworkInfo() != null
&& conectivtyManager.getActiveNetworkInfo().isAvailable()
&& conectivtyManager.getActiveNetworkInfo().isConnected();
return conectado;
}
示例10: createNewNoteNotification
import android.content.Context; //导入方法依赖的package包/类
public static void createNewNoteNotification(Context context) {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, context);
PendingIntent resultPendingIntent = ShareActivity.createNewNoteIntent(context, null);
/* Build notification */
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setOngoing(true)
.setSmallIcon(R.drawable.cic_orgzly_notification)
.setContentTitle(context.getString(R.string.new_note))
.setContentText(context.getString(R.string.tap_to_create_new_note))
.setColor(ContextCompat.getColor(context, R.color.notification))
.setContentIntent(resultPendingIntent)
.setPriority(NotificationCompat.PRIORITY_MIN); // Don't show icon on status bar
/* add sync action */
Intent syncIntent = new Intent(context, SyncService.class);
syncIntent.setAction(AppIntent.ACTION_SYNC_START);
PendingIntent syncPendingIntent = PendingIntent.getService(context, 0, syncIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.addAction(
R.drawable.ic_sync_white_24dp,
context.getString(R.string.sync),
syncPendingIntent);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(ONGOING_NEW_NOTE, builder.build());
}
示例11: scheduleRecommendationUpdate
import android.content.Context; //导入方法依赖的package包/类
private void scheduleRecommendationUpdate(Context context) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent recommendationIntent = new Intent(context, UpdateRecommendationsService.class);
PendingIntent alarmIntent = PendingIntent.getService(context, 0, recommendationIntent, 0);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, INITIAL_DELAY,
AlarmManager.INTERVAL_HALF_HOUR, alarmIntent);
}
示例12: getCurrentActivity
import android.content.Context; //导入方法依赖的package包/类
public static String getCurrentActivity(Context context){
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> forGroundActivity = activityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo currentActivity;
currentActivity = forGroundActivity.get(0);
return currentActivity.topActivity.getClassName();
}
示例13: isNetConnected
import android.content.Context; //导入方法依赖的package包/类
/**
* 检测网络是否连接
*/
public static boolean isNetConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkInfo[] infos = cm.getAllNetworkInfo();
if (infos != null) {
for (NetworkInfo ni : infos) {
if (ni.isConnected()) {
return true;
}
}
}
}
return false;
}
示例14: networkConnected
import android.content.Context; //导入方法依赖的package包/类
public static boolean networkConnected(Context context){
if (context != null){
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getActiveNetworkInfo();
if (info != null)
return info.isAvailable();
}
return false;
}
示例15: hideSoftKeyboard
import android.content.Context; //导入方法依赖的package包/类
/**
* 隐藏软键盘
*
* @param context
* @param view
*/
public static void hideSoftKeyboard(Context context, View view) {
if (view == null)
return;
InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (inputMethodManager.isActive())
inputMethodManager.hideSoftInputFromWindow(
view.getWindowToken(), 0);
}