Java Code Examples for android.app.Activity#getSystemService()
The following examples show how to use
android.app.Activity#getSystemService() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: BobEngine File: BobHelper.java License: GNU Lesser General Public License v2.1 | 6 votes |
/** * You should initialize your BobHelper in or after onCreate() of activity. * @param activity - The activity that this BobHelper is tied to. */ @SuppressLint("NewApi") public BobHelper(Activity activity) { this.activity = activity; wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE); size = new Point(); try { // Get screen dimensions wm.getDefaultDisplay().getRealSize(size); // New method, might not work on old devices screenWidth = size.x; screenHeight = size.y; } catch (NoSuchMethodError er) { // If new method didn't work, use depreciated methods screenWidth = wm.getDefaultDisplay().getWidth(); screenHeight = wm.getDefaultDisplay().getHeight(); } ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE); Log.i("info", Integer.toString(am.getMemoryClass()) + "MB ram available."); }
Example 2
Source Project: react-native-lock-task File: RNLockTaskModule.java License: MIT License | 6 votes |
@ReactMethod public void startLockTask() { try { Activity mActivity = reactContext.getCurrentActivity(); if (mActivity != null) { DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) mActivity.getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName mDPM = new ComponentName(mActivity, MyAdmin.class); if (myDevicePolicyManager.isDeviceOwnerApp(mActivity.getPackageName())) { String[] packages = {mActivity.getPackageName()}; myDevicePolicyManager.setLockTaskPackages(mDPM, packages); mActivity.startLockTask(); } else { mActivity.startLockTask(); } } } catch (Exception e) { } }
Example 3
Source Project: Lucid-Browser File: CustomWebView.java License: Apache License 2.0 | 6 votes |
public static boolean enqueDownload(final Activity c){ if (ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { DownloadManager manager = (DownloadManager) c.getSystemService(Context.DOWNLOAD_SERVICE); if (manager != null) { c.runOnUiThread(new Runnable() { @Override public void run() { Tools.toastString(R.string.download_started, c); } }); manager.enqueue(request); } return true; }else return false; }
Example 4
Source Project: sealtalk-android File: CommonUtils.java License: MIT License | 5 votes |
/** * 隐藏软键盘 * @param activity */ public static void hideKeyboard(Activity activity) { if(activity != null){ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if(imm.isActive()){ imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } } }
Example 5
Source Project: Learning-Resources File: Helper.java License: MIT License | 5 votes |
/** * Show the activity over the lockscreen and wake up the device. If you launched the app * manually both of these conditions are already true. If you deployed from the IDE, however, * this will save you from hundreds of power button presses and pattern swiping per day! */ public static void riseAndShine(Activity activity) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); PowerManager power = (PowerManager) activity.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock lock = power.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "wakeup!"); lock.acquire(100000); lock.release(); }
Example 6
Source Project: floatingsearchview File: Util.java License: Apache License 2.0 | 5 votes |
public static void closeSoftKeyboard(Activity activity) { View currentFocusView = activity.getCurrentFocus(); if (currentFocusView != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(currentFocusView.getWindowToken(), 0); } }
Example 7
Source Project: RxTools-master File: RxTextAutoZoom.java License: Apache License 2.0 | 5 votes |
public static void hideSoftKeyboard(Activity a) { InputMethodManager inputMethodManager = (InputMethodManager) a .getSystemService(Activity.INPUT_METHOD_SERVICE); if (a.getCurrentFocus() != null && a.getCurrentFocus().getWindowToken() != null) inputMethodManager.hideSoftInputFromWindow(a.getCurrentFocus().getWindowToken(), 0); }
Example 8
Source Project: CodenameOne File: Audio.java License: GNU General Public License v2.0 | 5 votes |
public Audio(Activity activity, MediaPlayer player, InputStream stream, Runnable onComplete) { this.activity = activity; this.player = player; this.stream = stream; if (onComplete != null) { addCompletionHandler(onComplete); } bindPlayerCleanupOnComplete(); AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE); int result = audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); }
Example 9
Source Project: MeiBaseModule File: SoftKeyboardUtils.java License: Apache License 2.0 | 5 votes |
public static void closeSoftKeyboard(Activity activity) { //隐藏软键盘 View view = activity.getWindow().peekDecorView(); if (view != null) { InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context .INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
Example 10
Source Project: mvp-sample File: ActivitySource.java License: Apache License 2.0 | 5 votes |
@Override void closeInputMethod() { Activity activity = getSource(); View focusView = activity.getCurrentFocus(); if (focusView != null) { InputMethodManager manager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); manager.hideSoftInputFromWindow(focusView.getWindowToken(), 0); } }
Example 11
Source Project: u2020 File: DebugViewContainer.java License: Apache License 2.0 | 5 votes |
/** * Show the activity over the lock-screen and wake up the device. If you launched the app manually * both of these conditions are already true. If you deployed from the IDE, however, this will * save you from hundreds of power button presses and pattern swiping per day! */ public static void riseAndShine(Activity activity) { activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED); PowerManager power = (PowerManager) activity.getSystemService(POWER_SERVICE); PowerManager.WakeLock lock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, "wakeup!"); lock.acquire(); lock.release(); }
Example 12
Source Project: debugdrawer File: RiseAndShineElement.java License: Apache License 2.0 | 5 votes |
/** * Show the activity over the lock-screen and wake up the device. If you launched the app manually * both of these conditions are already true. If you deployed from the IDE, however, this will * save you from hundreds of power button presses and pattern swiping per day! */ private static void riseAndShine(Activity activity) { activity.getWindow().addFlags(FLAG_SHOW_WHEN_LOCKED); PowerManager power = (PowerManager) activity.getSystemService(POWER_SERVICE); PowerManager.WakeLock lock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, "wakeup!"); lock.acquire(); lock.release(); }
Example 13
Source Project: enterprise-samples File: StatusFragment.java License: Apache License 2.0 | 5 votes |
/** * Unhides the AppRestrictionSchema sample in case it is hidden in this profile. * * @param activity The activity */ private void unhideApp(Activity activity) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE); devicePolicyManager.setApplicationHidden( EnforcerDeviceAdminReceiver.getComponentName(activity), Constants.PACKAGE_NAME_APP_RESTRICTION_SCHEMA, false); Toast.makeText(activity, "Enabled the app", Toast.LENGTH_SHORT).show(); mListener.onStatusUpdated(); }
Example 14
Source Project: Simpler File: InputMethodUtils.java License: Apache License 2.0 | 5 votes |
/** * 关闭软键盘 */ public static void closeSoftKeyboard(Activity activity) { //隐藏软键盘 View view = activity.getWindow().peekDecorView(); if (view != null) { InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } }
Example 15
Source Project: px-android File: ViewUtils.java License: MIT License | 5 votes |
public static void hideKeyboard(final Activity activity) { try { final EditText editText = (EditText) activity.getCurrentFocus(); final InputMethodManager imm = (InputMethodManager) activity.getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); } catch (final Exception ex) { } }
Example 16
Source Project: proofmode File: UIHelpers.java License: GNU General Public License v3.0 | 5 votes |
public static void hideSoftKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); View view = activity.getCurrentFocus(); if (view != null) inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); }
Example 17
Source Project: FriendBook File: InputMethodUtils.java License: GNU General Public License v3.0 | 5 votes |
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; }
Example 18
Source Project: FanXin-based-HuanXin File: MorePopWindow.java License: GNU General Public License v2.0 | 4 votes |
@SuppressLint("InflateParams") public MorePopWindow(final Activity context) { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conentView = inflater.inflate(R.layout.popupwindow_more, null); // 设置SelectPicPopupWindow的View this.setContentView(conentView); // 设置SelectPicPopupWindow弹出窗体的宽 this.setWidth(LayoutParams.WRAP_CONTENT); // 设置SelectPicPopupWindow弹出窗体的高 this.setHeight(LayoutParams.WRAP_CONTENT); // 设置SelectPicPopupWindow弹出窗体可点击 this.setFocusable(true); this.setOutsideTouchable(true); // 刷新状态 this.update(); // 实例化一个ColorDrawable颜色为半透明 ColorDrawable dw = new ColorDrawable(0000000000); // 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作 this.setBackgroundDrawable(dw); // 设置SelectPicPopupWindow弹出窗体动画效果 this.setAnimationStyle(R.style.AnimationPreview); RelativeLayout re_record =(RelativeLayout) conentView.findViewById(R.id.re_record); re_record.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { context.startActivity(new Intent(context,RecordsActivity.class)); MorePopWindow.this.dismiss(); } } ); }
Example 19
Source Project: buddycloud-android File: InputUtils.java License: Apache License 2.0 | 4 votes |
public static boolean isActive(Activity activity) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); return imm.isActive(); }
Example 20
Source Project: ESeal File: NetUtil.java License: Apache License 2.0 | 4 votes |
/** * 获取手机基站运行商 */ public static String getTelephonyNetWorkOperator(Activity activity) { TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE); return telephonyManager.getNetworkOperator(); }