本文整理匯總了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);
}