本文整理汇总了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);
}
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}