当前位置: 首页>>代码示例>>Java>>正文


Java Activity.getSystemService方法代码示例

本文整理汇总了Java中android.app.Activity.getSystemService方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.getSystemService方法的具体用法?Java Activity.getSystemService怎么用?Java Activity.getSystemService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.getSystemService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: hideSoftKeyboard

import android.app.Activity; //导入方法依赖的package包/类
public static void hideSoftKeyboard(Activity act) {
    InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
    if(inputMethodManager != null ) {
        View localView = act.getCurrentFocus();
        if(localView != null && localView.getWindowToken() != null ) {
            IBinder windowToken = localView.getWindowToken();
            inputMethodManager.hideSoftInputFromWindow(windowToken, 0);
        }
    }
}
 
开发者ID:Louis19910615,项目名称:youkes_browser,代码行数:11,代码来源:SoftKeyboardUtil.java

示例2: hasNetworkConnection

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Validate the network connection. Supports checking for WiFi only when
 * this settings has been set to true.
 *
 * @param activity Activity
 * @return Has network connection
 */
public static boolean hasNetworkConnection(Activity activity) {
    ConnectivityManager connMgr = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

    if (networkInfo == null)
        return false;

    if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(Settings.PREF_WIFI_ONLY, false))
        return networkInfo.getType() == ConnectivityManager.TYPE_WIFI;

    return networkInfo.isConnected();
}
 
开发者ID:linklux,项目名称:android-schedules,代码行数:20,代码来源:NetUtil.java

示例3: hideKeyboard

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Hide keyboard, the view is automatically detected from the activity
 *
 * @param a Activity
 */
public static void hideKeyboard(Activity a) {
    // Check if no view has focus:
    try {
        View view = a.getCurrentFocus();
        if (view != null) {
            InputMethodManager inputManager = (InputMethodManager) a.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    } catch (Throwable e) {
        //Not the end of the world. Keyborad didn't hide, that's it.
        e.printStackTrace();
    }
}
 
开发者ID:yajnesh,项目名称:AndroidGeneralUtils,代码行数:19,代码来源:ViewUtil.java

示例4: copyToClipboard

import android.app.Activity; //导入方法依赖的package包/类
public static void copyToClipboard(Activity activity, String textToCopy) {
    ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText("Remindy text", textToCopy);
    clipboard.setPrimaryClip(clip);

    String toastMsg = String.format(Locale.getDefault(), activity.getResources().getString(R.string.dialog_text_attachment_text_copied_clipboard), textToCopy);
    Toast.makeText(activity, toastMsg, Toast.LENGTH_SHORT).show();
}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:9,代码来源:ClipboardUtil.java

示例5: ControllerDataProvider

import android.app.Activity; //导入方法依赖的package包/类
public ControllerDataProvider(Activity activity, int sensorRefreshSpeed) {
    fusedEulerAngles = new float[3];
    fusedQuaternion = new Quaternion();
    fusedQuaternion.loadIdentityQuat();
    zeroQuaternion = new Quaternion();
    zeroQuaternion.loadIdentityQuat();
    finalFusedQuaternion = new Quaternion();
    fusedQuaternion.loadIdentityQuat();
    sensorManager = (SensorManager) activity.getSystemService(SENSOR_SERVICE);
    currentOrientationProvider = new ImprovedOrientationSensor1Provider(sensorManager, sensorRefreshSpeed);
}
 
开发者ID:peter10110,项目名称:Android-SteamVR-controller,代码行数:12,代码来源:ControllerDataProvider.java

示例6: hideSoftInput

import android.app.Activity; //导入方法依赖的package包/类
public static boolean hideSoftInput(Activity activity) {
    if (activity.getCurrentFocus() != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        return imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
    }
    return false;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:IMEUtils.java

示例7: showKeyboard

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 显示软键盘
 * @param activity
 */
public static void showKeyboard(Activity activity) {
    if (activity != null) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (!imm.isActive()) {
            imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0);
        }
    }
}
 
开发者ID:zqHero,项目名称:rongyunDemo,代码行数:13,代码来源:CommonUtils.java

示例8: hideSoftInput

import android.app.Activity; //导入方法依赖的package包/类
/**
 * @param mActivity
 * @param token
 */
private void hideSoftInput(Activity mActivity, IBinder token) {
    if (token != null) {
        InputMethodManager im = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
开发者ID:devzwy,项目名称:KUtils,代码行数:11,代码来源:HideUtil.java

示例9: NoNetWorkNotice

import android.app.Activity; //导入方法依赖的package包/类
private NoNetWorkNotice(final Activity context){

        wdm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

        mView = View.inflate(context, R.layout.no_net_worke_layout , null);
        mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.getApplicationContext().startActivity(intent);


            }
        });
        //设置LayoutParams(全局变量)相关参数
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_APPLICATION,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT);

        params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;


    }
 
开发者ID:liu-xiao-dong,项目名称:JD-Test,代码行数:28,代码来源:NoNetWorkNotice.java

示例10: getUDID

import android.app.Activity; //导入方法依赖的package包/类
@SuppressLint("HardwareIds")
public static String getUDID(Activity activity) {
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        String tmDevice = "" + (tm != null ? tm.getDeviceId() : null);
        String tmSerial = "" + (tm != null ? tm.getSimSerialNumber() : null);
        String androidId = "" + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
        UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

        return deviceUuid.toString();
    }
    else{
        return Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
    }
}
 
开发者ID:afiqiqmal,项目名称:MVP-Android,代码行数:16,代码来源:DeviceUtils.java

示例11: hideSoftInput

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 多种隐藏软件盘方法的其中一种
 *
 * @param token
 */
public static void hideSoftInput(Activity activity, IBinder token) {
    if (token != null) {
        InputMethodManager im = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        im.hideSoftInputFromWindow(token,
                InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:13,代码来源:AppTools.java

示例12: getUDID

import android.app.Activity; //导入方法依赖的package包/类
@SuppressLint("HardwareIds")
public static String getUDID(Activity activity) {
    if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
        String tmDevice = "" + tm.getDeviceId();
        String tmSerial = "" + tm.getSimSerialNumber();
        String androidId = "" + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
        UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

        return deviceUuid.toString();
    }
    else{
        return Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
    }
}
 
开发者ID:afiqiqmal,项目名称:My-Android-Base-Code,代码行数:16,代码来源:DeviceUtils.java

示例13: hideKeyboard

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Hides the onscreen keyboard if it is visisble
 */
public static void hideKeyboard(Activity activity) {
	// Check if no view has focus:
	View view = activity.getCurrentFocus();
	if (view != null) {
		InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
	}
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:12,代码来源:Service.java

示例14: showKeyboard

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Show the soft keyboard.
 * @param activity the current activity
 */
public static void showKeyboard(@Nullable Activity activity) {
    if (activity == null) return;
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
 
开发者ID:TryGhost,项目名称:Ghost-Android,代码行数:10,代码来源:KeyboardUtils.java

示例15: lockOrientation

import android.app.Activity; //导入方法依赖的package包/类
public static void lockOrientation(Activity activity) {
    if (activity == null || prevOrientation != -10) {
        return;
    }
    try {
        prevOrientation = activity.getRequestedOrientation();
        WindowManager manager = (WindowManager)activity.getSystemService(Activity.WINDOW_SERVICE);
        if (manager != null && manager.getDefaultDisplay() != null) {
            int rotation = manager.getDefaultDisplay().getRotation();
            int orientation = activity.getResources().getConfiguration().orientation;

            if (rotation == Surface.ROTATION_270) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_90) {
                if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                }
            } else if (rotation == Surface.ROTATION_0) {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                }
            } else {
                if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                } else {
                    activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                }
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:42,代码来源:AndroidUtilities.java


注:本文中的android.app.Activity.getSystemService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。