當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。