當前位置: 首頁>>代碼示例>>Java>>正文


Java PowerManager類代碼示例

本文整理匯總了Java中android.os.PowerManager的典型用法代碼示例。如果您正苦於以下問題:Java PowerManager類的具體用法?Java PowerManager怎麽用?Java PowerManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PowerManager類屬於android.os包,在下文中一共展示了PowerManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import android.os.PowerManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
  mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
      PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "AlarmActivity");
  mWakeLock.acquire(2 * 60 * 1000L);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    window.getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    window.setStatusBarColor(Color.TRANSPARENT);
  }

  setContentView(R.layout.activity_alarm);
  if (getActivityComponent() != null) {
    getActivityComponent().inject(this);
    alarmPresenter.onAttach(this);
  }
  initViews();
  bindEvents();
  processIntent();
}
 
開發者ID:Arjun-sna,項目名稱:LocationAware,代碼行數:27,代碼來源:AlarmActivity.java

示例2: onReceive

import android.os.PowerManager; //導入依賴的package包/類
@Override
public void onReceive(Context c, Intent i) {
  final long alarmid = i.getLongExtra(ALARM_ID, -1);

  @SuppressWarnings("deprecation")  // SCREEN_DIM_WAKE_LOCK
  PowerManager.WakeLock w =
    ((PowerManager)c.getSystemService(Context.POWER_SERVICE))
    .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK |
                 PowerManager.ACQUIRE_CAUSES_WAKEUP, "wake id " + nextid);
  w.setReferenceCounted(false);
  w.acquire();
  locks.put(nextid, w);
  Log.i(TAG, "Acquired lock " + nextid + " for alarm " + alarmid);

  c.startService(new Intent(c, AlarmNotificationService.class)
                 .putExtra(ALARM_ID, alarmid)
                 .putExtra(COMMAND, TRIGGER_ALARM_NOTIFICATION)
                 .putExtra(WAKELOCK_ID, nextid++));
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:20,代碼來源:AlarmNotificationService.java

示例3: onRun

import android.os.PowerManager; //導入依賴的package包/類
@Override
public void onRun() throws IOException {
  Log.w("DirectoryRefreshJob", "DirectoryRefreshJob.onRun()");
  PowerManager          powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  PowerManager.WakeLock wakeLock     = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Directory Refresh");

  try {
    wakeLock.acquire();
    if (recipients == null) {
      DirectoryHelper.refreshDirectory(context, KeyCachingService.getMasterSecret(context));
    } else {
      DirectoryHelper.refreshDirectoryFor(context, masterSecret, recipients, TextSecurePreferences.getLocalNumber(context));
    }
    SecurityEvent.broadcastSecurityUpdateEvent(context);
  } finally {
    if (wakeLock.isHeld()) wakeLock.release();
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:19,代碼來源:DirectoryRefreshJob.java

示例4: LinphoneManager

import android.os.PowerManager; //導入依賴的package包/類
protected LinphoneManager(final Context c) {
	sExited = false;
	echoTesterIsRunning = false;
	mServiceContext = c;
	basePath = c.getFilesDir().getAbsolutePath();
	mLPConfigXsd = basePath + "/lpconfig.xsd";
	mLinphoneFactoryConfigFile = basePath + "/linphonerc";
	mLinphoneConfigFile = basePath + "/.linphonerc";
	mLinphoneRootCaFile = basePath + "/rootca.pem";
	mRingSoundFile = basePath + "/ringtone.mkv";
	mRingbackSoundFile = basePath + "/ringback.wav";
	mPauseSoundFile = basePath + "/hold.mkv";
	mChatDatabaseFile = basePath + "/linphone-history.db";
	mCallLogDatabaseFile = basePath + "/linphone-log-history.db";
	mFriendsDatabaseFile = basePath + "/linphone-friends.db";
	mErrorToneFile = basePath + "/error.wav";
	mUserCertificatePath = basePath;

	mPrefs = LinphonePreferences.instance();
	mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
	mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
	mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
	mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
	mR = c.getResources();
	mPendingChatFileMessage = new ArrayList<LinphoneChatMessage>();
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:27,代碼來源:LinphoneManager.java

示例5: run

import android.os.PowerManager; //導入依賴的package包/類
@Override
public void run() {

    super.run();
    PowerManager.WakeLock lock = getLock(mContext);
    while (isRunning) {
        AnimeDownloadTask task = mTaskQueue.poll();
        if (task != null) {
            if (!lock.isHeld()) {
                lock.acquire();
            }
            mDownloadingTasks.add(task);
            task.execute();
        }
    }
    if (lock.isHeld()) {
        lock.release();
    }
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:20,代碼來源:AnimeDownloadManager.java

示例6: LockManager

import android.os.PowerManager; //導入依賴的package包/類
public LockManager(Context context) {
  PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  fullLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "RedPhone Full");
  partialLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "RedPhone Partial");
  proximityLock = new ProximityLock(pm);

  WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
  wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "RedPhone Wifi");

  fullLock.setReferenceCounted(false);
  partialLock.setReferenceCounted(false);
  wifiLock.setReferenceCounted(false);

  accelerometerListener = new AccelerometerListener(context, new AccelerometerListener.OrientationListener() {
    @Override
    public void orientationChanged(int newOrientation) {
      orientation = newOrientation;
      Log.d(TAG, "Orentation Update: " + newOrientation);
      updateInCallLockState();
    }
  });

  wifiLockEnforced = isWifiPowerActiveModeEnabled(context);
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:25,代碼來源:LockManager.java

示例7: wakeAndUnlock

import android.os.PowerManager; //導入依賴的package包/類
private void wakeAndUnlock()
{
    //獲取電源管理器對象
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //獲取PowerManager.WakeLock對象,後麵的參數|表示同時傳入兩個值,最後的是調試用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

    //點亮屏幕
    wl.acquire(1000);

    //得到鍵盤鎖管理器對象
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    kl = km.newKeyguardLock("unLock");

    //解鎖
    kl.disableKeyguard();

}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:20,代碼來源:AppCompatDlalog.java

示例8: acquireWakeLocks

import android.os.PowerManager; //導入依賴的package包/類
/**
 *
 */
private void acquireWakeLocks() {
    if(_wakeLock == null) {
        PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
        _wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BlockchainServiceLockTag");
    }

    if (_wifiLock == null) {
        WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        _wifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "BlockchainServiceWifiLockTag");
    }

    if (!_wakeLock.isHeld())
        _wakeLock.acquire();

    if (!_wifiLock.isHeld())
        _wifiLock.acquire();
}
 
開發者ID:ehanoc,項目名稱:xwallet,代碼行數:21,代碼來源:BlockchainService.java

示例9: toggleWakeUpWithProximityFeature

import android.os.PowerManager; //導入依賴的package包/類
private static void toggleWakeUpWithProximityFeature(boolean enabled) {
    try {
        if (enabled) {
            mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
            mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
            mWakeLock = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE))
                    .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
        } else {
            unregisterProxSensorListener();
            mProxSensor = null;
            mSensorManager = null;
            mWakeLock = null;
        }
        if (DEBUG) log("toggleWakeUpWithProximityFeature: " + enabled);
    } catch (Throwable t) {
        XposedBridge.log(t);
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:19,代碼來源:ModPower.java

示例10: run

import android.os.PowerManager; //導入依賴的package包/類
@Override
public void run() {
  notification              = initializeBackgroundNotification();
  PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
  WakeLock     wakeLock     = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Migration");

  try {
    wakeLock.acquire();

    setState(new ImportState(ImportState.STATE_MIGRATING_BEGIN, null));

    SmsMigrator.migrateDatabase(ApplicationMigrationService.this,
                                masterSecret,
                                ApplicationMigrationService.this);

    setState(new ImportState(ImportState.STATE_MIGRATING_COMPLETE, null));

    setDatabaseImported(ApplicationMigrationService.this);
    stopForeground(true);
    notifyImportComplete();
    stopSelf();
  } finally {
    wakeLock.release();
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:26,代碼來源:ApplicationMigrationService.java

示例11: onStartCommand

import android.os.PowerManager; //導入依賴的package包/類
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    PowerManager.WakeLock lock = getLock(this.getApplicationContext());

    if (!lock.isHeld() || (flags & START_FLAG_REDELIVERY) != 0) {
        lock.acquire();
    }

    if (mServiceHandler != null) {
        if (intent != null && intent.getExtras() != null) {
            // For each start request, send a message to start a job and deliver the
            // start ID so we know which request we're stopping when we finish the job
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.setData(intent.getExtras());
            mServiceHandler.sendMessage(msg);
        } else
            stopSelf();
    }

    // If we get killed, after returning from here, restart
    return START_STICKY;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:25,代碼來源:ParseAnimeService.java

示例12: wakeAndUnlock

import android.os.PowerManager; //導入依賴的package包/類
private void wakeAndUnlock() {
    //獲取電源管理器對象
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    //獲取PowerManager.WakeLock對象,後麵的參數|表示同時傳入兩個值,最後的是調試用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

    //點亮屏幕
    wl.acquire(1000);

    //得到鍵盤鎖管理器對象
    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    kl = km.newKeyguardLock("unLock");

    //解鎖
    kl.disableKeyguard();

}
 
開發者ID:xmlxin,項目名稱:ReplyMessage,代碼行數:19,代碼來源:AutoReplyService.java

示例13: wakeAndUnlock

import android.os.PowerManager; //導入依賴的package包/類
public static void wakeAndUnlock() {
    //獲取電源管理器對象
    PowerManager pm = getPowerManager();

    //獲取PowerManager.WakeLock對象,後麵的參數|表示同時傳入兩個值,最後的是調試用的Tag
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "bright");

    //點亮屏幕
    wl.acquire(1000);

    //得到鍵盤鎖管理器對象
    KeyguardManager km = getKeyguardManager();
    KeyguardManager.KeyguardLock kl = km.newKeyguardLock("unLock");

    //解鎖
    kl.disableKeyguard();
}
 
開發者ID:A-Miracle,項目名稱:QiangHongBao,代碼行數:18,代碼來源:NotifyUtils.java

示例14: wakeScreen

import android.os.PowerManager; //導入依賴的package包/類
/**
 * Waking up the screen
 * * * */
private static void wakeScreen(Context context){

    // Waking the screen so the user will see the notification
    PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);


    boolean isScreenOn;

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT_WATCH)
        isScreenOn = pm.isScreenOn();
    else
        isScreenOn = pm.isInteractive();

    if(!isScreenOn)
    {

        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                |PowerManager.ON_AFTER_RELEASE
                |PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyLock");

        wl.acquire(5000);
        wl.release();
    }
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:28,代碼來源:NotificationUtils.java

示例15: keepAwake

import android.os.PowerManager; //導入依賴的package包/類
/**
 * Put the service in a foreground state to prevent app from being killed
 * by the OS.
 */
private void keepAwake() {
    JSONObject settings = BackgroundMode.getSettings();
    boolean isSilent    = settings.optBoolean("silent", false);

    if (!isSilent) {
        startForeground(NOTIFICATION_ID, makeNotification());
    }

    PowerManager powerMgr = (PowerManager)
            getSystemService(POWER_SERVICE);

    wakeLock = powerMgr.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK, "BackgroundMode");

    wakeLock.acquire();
}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:21,代碼來源:ForegroundService.java


注:本文中的android.os.PowerManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。