当前位置: 首页>>代码示例>>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;未经允许,请勿转载。