Java Code Examples for android.app.Activity#getSystemService()

The following examples show how to use android.app.Activity#getSystemService() . 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 File: CustomWebView.java    From Lucid-Browser with Apache License 2.0 6 votes vote down vote up
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 2
Source File: BobHelper.java    From BobEngine with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 3
Source File: RNLockTaskModule.java    From react-native-lock-task with MIT License 6 votes vote down vote up
@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 4
Source File: DebugViewContainer.java    From u2020 with Apache License 2.0 5 votes vote down vote up
/**
 * 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 5
Source File: InputMethodUtils.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: UIHelpers.java    From proofmode with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: ViewUtils.java    From px-android with MIT License 5 votes vote down vote up
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 8
Source File: InputMethodUtils.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 关闭软键盘
 */
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 9
Source File: StatusFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
/**
 * 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 10
Source File: RiseAndShineElement.java    From debugdrawer with Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
Source File: ActivitySource.java    From mvp-sample with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: SoftKeyboardUtils.java    From MeiBaseModule with Apache License 2.0 5 votes vote down vote up
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 13
Source File: Audio.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: RxTextAutoZoom.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
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 15
Source File: Util.java    From floatingsearchview with Apache License 2.0 5 votes vote down vote up
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 16
Source File: Helper.java    From Learning-Resources with MIT License 5 votes vote down vote up
/**
 * 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 17
Source File: CommonUtils.java    From sealtalk-android with MIT License 5 votes vote down vote up
/**
 * 隐藏软键盘
 * @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 18
Source File: MorePopWindow.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
@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 File: NetUtil.java    From ESeal with Apache License 2.0 4 votes vote down vote up
/**
 * 获取手机基站运行商
 */
public static String getTelephonyNetWorkOperator(Activity activity) {
    TelephonyManager telephonyManager = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getNetworkOperator();
}
 
Example 20
Source File: InputUtils.java    From buddycloud-android with Apache License 2.0 4 votes vote down vote up
public static boolean isActive(Activity activity) {
	InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
	return imm.isActive();
}