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