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


Java Application.getSystemService方法代码示例

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


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

示例1: onStart

import android.app.Application; //导入方法依赖的package包/类
@SuppressLint("MissingPermission")
@Override
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
 
开发者ID:ebridfighter,项目名称:GongXianSheng,代码行数:17,代码来源:UnlockDeviceAndroidJUnitRunner.java

示例2: getAppName

import android.app.Application; //导入方法依赖的package包/类
private static String getAppName(Application application, int pID) {
    String processName = null;
    ActivityManager am = (ActivityManager) application.getSystemService(Context.ACTIVITY_SERVICE);
    List l = am.getRunningAppProcesses();
    Iterator i = l.iterator();
    PackageManager pm = application.getPackageManager();
    while (i.hasNext()) {
        ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next());
        try {
            if (info.pid == pID) {
                processName = info.processName;
                return processName;
            }
        } catch (Exception e) {
            // Log.d("Process", "Error>> :"+ e.toString());
        }
    }
    return processName;
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:20,代码来源:RApplication.java

示例3: addWindow

import android.app.Application; //导入方法依赖的package包/类
static void addWindow(Application app) {
    activityLifecycleObservable = new ActivityLifecycleObservable();
    activityTaskView = new ActivityTaskView(app);
    activityTaskView.setObservable(activityLifecycleObservable);

    qhandler = new QueueHandler();

    WindowManager windowManager = (WindowManager) app.getSystemService(Context.WINDOW_SERVICE);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.type = WindowManager.LayoutParams.TYPE_PHONE;
    params.format = PixelFormat.RGBA_8888;
    params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.START | Gravity.TOP;
    params.x = 0;
    params.y = app.getResources().getDisplayMetrics().heightPixels;
    windowManager.addView(activityTaskView, params);

    app.registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
}
 
开发者ID:rome753,项目名称:ActivityTaskView,代码行数:22,代码来源:ActivityTask.java

示例4: saveOneRecord

import android.app.Application; //导入方法依赖的package包/类
/**
 * save one activity record
 * @param activityRecord record to save
 * @return the file path this record is saved
 */
public static boolean saveOneRecord(ActivityRecord activityRecord) {
    boolean ret = saveOneRecord(activityRecord.toJsonString());
    if (ret) {
        Application app = StallBuster.getInstance().getApp();
        Intent intent = new Intent(StallBuster.getInstance().getApp(), ReportListActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(StallBuster.getInstance().getApp(), 1, intent, FLAG_UPDATE_CURRENT);
        NotificationManager nm = (NotificationManager)app.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(NOTIFICATION_ID);
        Notification notification = new NotificationCompat.Builder(app)
                .setAutoCancel(true)
                .setContentTitle(app.getString(R.string.notification_title, activityRecord.cost, activityRecord.activity_name))
                .setContentText(app.getString(R.string.notification_text))
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .setContentIntent(pendingIntent)
                .build();
        nm.notify(NOTIFICATION_ID, notification);
    }
    return ret;
}
 
开发者ID:zhangjianli,项目名称:StallBuster,代码行数:26,代码来源:RecordsStore.java

示例5: onStart

import android.app.Application; //导入方法依赖的package包/类
@SuppressWarnings("MissingPermission")
@Override
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = ((PowerManager) application.getSystemService(POWER_SERVICE));
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
 
开发者ID:OHoussein,项目名称:Android-Show-Reader,代码行数:17,代码来源:UnlockDeviceAndroidJUnitRunner.java

示例6: checkIsMainProcess

import android.app.Application; //导入方法依赖的package包/类
public static boolean checkIsMainProcess(Application app) {
    ActivityManager activityManager = (ActivityManager) app.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningAppProcessInfo> runningAppProcessInfoList = activityManager.getRunningAppProcesses();
    if (null == runningAppProcessInfoList) {
        return false;
    }

    String currProcessName = null;
    int currPid = android.os.Process.myPid();
    //find the process name
    for (RunningAppProcessInfo processInfo : runningAppProcessInfoList) {
        if (null != processInfo && processInfo.pid == currPid) {
            currProcessName = processInfo.processName;
        }
    }

    //is current process the main process
    if (!TextUtils.equals(currProcessName, app.getPackageName())) {
        return false;
    }

    return true;
}
 
开发者ID:zyc945,项目名称:AppVisibilityDetector,代码行数:24,代码来源:AppVisibilityDetector.java

示例7: onStart

import android.app.Application; //导入方法依赖的package包/类
@Override
@SuppressLint("MissingPermission")
public void onStart() {
    Application application = (Application) getTargetContext().getApplicationContext();
    String simpleName = UnlockDeviceAndroidJUnitRunner.class.getSimpleName();
    // Unlock the device so that the tests can input keystrokes.
    ((KeyguardManager) application.getSystemService(KEYGUARD_SERVICE))
            .newKeyguardLock(simpleName)
            .disableKeyguard();
    // Wake up the screen.
    PowerManager powerManager = (PowerManager) application.getSystemService(POWER_SERVICE);
    mWakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP |
            ON_AFTER_RELEASE, simpleName);
    mWakeLock.acquire();
    super.onStart();
}
 
开发者ID:schul-cloud,项目名称:schulcloud-mobile-android,代码行数:17,代码来源:UnlockDeviceAndroidJUnitRunner.java

示例8: callApplicationOnCreate

import android.app.Application; //导入方法依赖的package包/类
@Override
public void callApplicationOnCreate(final Application app) {
    // Unlock the screen
    KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
    keyguard.newKeyguardLock(getClass().getSimpleName()).disableKeyguard();

    // Start a wake lock
    PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
    mWakeLock = power.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                    | PowerManager.ON_AFTER_RELEASE, getClass().getSimpleName());
    mWakeLock.acquire();
    super.callApplicationOnCreate(app);

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:TestRunner.java

示例9: getLastBestLocation

import android.app.Application; //导入方法依赖的package包/类
/**
 * Returns the most accurate and timely previously detected location. Where
 * the last result is beyond the specified maximum distance or latency a
 * one-off location update is returned via the {@link LocationListener}
 *
 * @param minDistance
 *            - meter Minimum distance before we require a location update.
 * @param latestTime
 *            - minisecond the lastest time required between location
 *            updates.
 * @return The most accurate and / or timely previously detected location.
 */
public static Location getLastBestLocation(Application application, int minDistance, long latestTime) {
	LocationManager locationManager = (LocationManager) application
			.getSystemService(Context.LOCATION_SERVICE);
	Location bestResult = null;
	float bestAccuracy = Float.MAX_VALUE;
	long bestTime = Long.MIN_VALUE;

	// Iterate through all the providers on the system, keeping
	// note of the most accurate result within the acceptable time limit.
	// If no result is found within maxTime, return the newest Location.
	List<String> matchingProviders = locationManager.getAllProviders();
	for (String provider : matchingProviders) {
		Location location = locationManager.getLastKnownLocation(provider);

		if (location != null) {
			float accuracy = location.getAccuracy();
			long time = location.getTime();

			if ((time > latestTime && accuracy < bestAccuracy)) {
				bestResult = location;
				bestAccuracy = accuracy;
				bestTime = time;
			} else if (time < latestTime && bestAccuracy == Float.MAX_VALUE
					&& time > bestTime) {
				bestResult = location;
				bestTime = time;
			}
		}
	}


	return bestResult;
}
 
开发者ID:Ericliu001,项目名称:RosterManager,代码行数:46,代码来源:LastLocationFinder.java

示例10: estimateContentSize

import android.app.Application; //导入方法依赖的package包/类
/**
 * Provides an estimate of the contents size.
 *
 * The estimate is likely to be incorrect. This is not a problem, as the aim
 * is to avoid getting a different layout and resources than needed at
 * render time.
 * @param application The application to use for getting resources.
 * @param convertToDp Whether the value should be converted to dp from pixels.
 * @return The estimated prerender size in pixels or dp.
 */
public static Rect estimateContentSize(Application application, boolean convertToDp) {
    // The size is estimated as:
    // X = screenSizeX
    // Y = screenSizeY - top bar - bottom bar - custom tabs bar
    // The bounds rectangle includes the bottom bar and the custom tabs bar as well.
    Rect screenBounds = new Rect();
    Point screenSize = new Point();
    WindowManager wm = (WindowManager) application.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getSize(screenSize);
    Resources resources = application.getResources();
    int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android");
    try {
        screenSize.y -= resources.getDimensionPixelSize(statusBarId);
    } catch (Resources.NotFoundException e) {
        // Nothing, this is just a best effort estimate.
    }
    screenBounds.set(0,
            resources.getDimensionPixelSize(R.dimen.custom_tabs_control_container_height),
            screenSize.x, screenSize.y);

    if (convertToDp) {
        float density = resources.getDisplayMetrics().density;
        screenBounds.top = (int) Math.ceil(screenBounds.top / density);
        screenBounds.left = (int) Math.ceil(screenBounds.left / density);
        screenBounds.right = (int) Math.ceil(screenBounds.right / density);
        screenBounds.bottom = (int) Math.ceil(screenBounds.bottom / density);
    }
    return screenBounds;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:40,代码来源:ExternalPrerenderHandler.java

示例11: initConnectivityManager

import android.app.Application; //导入方法依赖的package包/类
/**
 * Initializes the {@link ConnectivityManager}.
 */
private void initConnectivityManager(Application application) {
  connectivityManager = (ConnectivityManager) application.getSystemService(Context.CONNECTIVITY_SERVICE);
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:7,代码来源:NavigationViewModel.java

示例12: NetworkConnectionChecker

import android.app.Application; //导入方法依赖的package包/类
public NetworkConnectionChecker(Application context) {
    this.connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    context.registerReceiver(new NetworkStateReceiver(), intentFilter);
}
 
开发者ID:mobilemaster128,项目名称:quickblox-android,代码行数:6,代码来源:NetworkConnectionChecker.java

示例13: fixFocusedViewLeak

import android.app.Application; //导入方法依赖的package包/类
/**
 * Fix for https://code.google.com/p/android/issues/detail?id=171190 .
 *
 * When a view that has focus gets detached, we wait for the main thread to be idle and then
 * check if the InputMethodManager is leaking a view. If yes, we tell it that the decor view got
 * focus, which is what happens if you press home and come back from recent apps. This replaces
 * the reference to the detached view with a reference to the decor view.
 *
 * Should be called from {@link Activity#onCreate(android.os.Bundle)} )}.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void fixFocusedViewLeak(Application application) {

    // Don't know about other versions yet.
    if (SDK_INT < KITKAT || SDK_INT > 23) {
        return;
    }

    final InputMethodManager inputMethodManager =
            (InputMethodManager) application.getSystemService(INPUT_METHOD_SERVICE);

    final Field mServedViewField;
    final Field mHField;
    final Method finishInputLockedMethod;
    final Method focusInMethod;
    try {
        mServedViewField = InputMethodManager.class.getDeclaredField("mServedView");
        mServedViewField.setAccessible(true);
        mHField = InputMethodManager.class.getDeclaredField("mServedView");
        mHField.setAccessible(true);
        finishInputLockedMethod = InputMethodManager.class.getDeclaredMethod("finishInputLocked");
        finishInputLockedMethod.setAccessible(true);
        focusInMethod = InputMethodManager.class.getDeclaredMethod("focusIn", View.class);
        focusInMethod.setAccessible(true);
    } catch (NoSuchMethodException | NoSuchFieldException unexpected) {
        Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
        return;
    }

    application.registerActivityLifecycleCallbacks(new LifecycleCallbacksAdapter() {
        @Override
        public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
            ReferenceCleaner cleaner =
                    new ReferenceCleaner(inputMethodManager, mHField, mServedViewField,
                            finishInputLockedMethod);
            View rootView = activity.getWindow().getDecorView().getRootView();
            ViewTreeObserver viewTreeObserver = rootView.getViewTreeObserver();
            viewTreeObserver.addOnGlobalFocusChangeListener(cleaner);
        }
    });
}
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:52,代码来源:IMMLeaks.java

示例14: obtain

import android.app.Application; //导入方法依赖的package包/类
@SuppressLint("WrongConstant")
public static BirthdayManager obtain(Application application){
    return (BirthdayManager) application.getSystemService(BIRTHDAY_SERVICE);
}
 
开发者ID:PocketX,项目名称:PocketKnell,代码行数:5,代码来源:Injector.java

示例15: BarricadeShakeListener

import android.app.Application; //导入方法依赖的package包/类
public BarricadeShakeListener(Application application) {
  this.application = application;
  this.sensorManager = (SensorManager) application.getSystemService(SENSOR_SERVICE);

  application.registerActivityLifecycleCallbacks(this);
}
 
开发者ID:mutualmobile,项目名称:Barricade,代码行数:7,代码来源:BarricadeShakeListener.java


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