當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.getSystemService方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lo625090140,項目名稱:lqrwechatrongcloud,代碼行數:19,代碼來源:NetUtils.java

示例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;
}
 
開發者ID:skydoves,項目名稱:PowerMenu,代碼行數:39,代碼來源:MenuListAdapter.java

示例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);
    }
}
 
開發者ID:monthlypub,項目名稱:SmingZZick_App,代碼行數:14,代碼來源:AttackManager.java

示例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;
}
 
開發者ID:yy941002,項目名稱:retrofit-OurRetrofit,代碼行數:18,代碼來源:HttpUtil.java

示例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;
}
 
開發者ID:Yobin123,項目名稱:PinTuGame,代碼行數:13,代碼來源:ScreenUtil.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:8,代碼來源:Util.java

示例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;
    }
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:16,代碼來源:AsyncTaskManager.java

示例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);
}
 
開發者ID:YuntaoWei,項目名稱:PictureShow,代碼行數:6,代碼來源:ConfirmDialog.java

示例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;
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:9,代碼來源:Utils.java

示例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());
}
 
開發者ID:orgzly,項目名稱:orgzly-android,代碼行數:31,代碼來源:Notifications.java

示例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);
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:9,代碼來源:RecommendationReceiver.java

示例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();
}
 
開發者ID:natjs,項目名稱:nat-network-stream,代碼行數:8,代碼來源:Util.java

示例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;
}
 
開發者ID:piscessu,項目名稱:hellomvp,代碼行數:18,代碼來源:NetWorkUtil.java

示例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;
    }
 
開發者ID:TonnyL,項目名稱:Espresso,代碼行數:12,代碼來源:NetworkUtil.java

示例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);
}
 
開發者ID:Zweihui,項目名稱:Aurora,代碼行數:16,代碼來源:DeviceUtils.java


注:本文中的android.content.Context.getSystemService方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。