本文整理匯總了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();
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例11: initConnectivityManager
import android.app.Application; //導入方法依賴的package包/類
/**
* Initializes the {@link ConnectivityManager}.
*/
private void initConnectivityManager(Application application) {
connectivityManager = (ConnectivityManager) application.getSystemService(Context.CONNECTIVITY_SERVICE);
}
示例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);
}
示例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);
}
});
}
示例14: obtain
import android.app.Application; //導入方法依賴的package包/類
@SuppressLint("WrongConstant")
public static BirthdayManager obtain(Application application){
return (BirthdayManager) application.getSystemService(BIRTHDAY_SERVICE);
}
示例15: BarricadeShakeListener
import android.app.Application; //導入方法依賴的package包/類
public BarricadeShakeListener(Application application) {
this.application = application;
this.sensorManager = (SensorManager) application.getSystemService(SENSOR_SERVICE);
application.registerActivityLifecycleCallbacks(this);
}