当前位置: 首页>>代码示例>>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;未经允许,请勿转载。