Example usage for android.os PowerManager ACQUIRE_CAUSES_WAKEUP

List of usage examples for android.os PowerManager ACQUIRE_CAUSES_WAKEUP

Introduction

In this page you can find the example usage for android.os PowerManager ACQUIRE_CAUSES_WAKEUP.

Prototype

int ACQUIRE_CAUSES_WAKEUP

To view the source code for android.os PowerManager ACQUIRE_CAUSES_WAKEUP.

Click Source Link

Document

Wake lock flag: Turn the screen on when the wake lock is acquired.

Usage

From source file:com.mowares.massagerexpressclient.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from  w ww .  j a  v a 2  s  . c  o  m*/

private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    //notification.setLatestEventInfo(context, title, message, intent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:com.simicart.core.notification.GCMIntentService.java

private void onRecieveMessage(Context context) {
    // Sang man hinh khi co notification
    PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
    WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire(5000);/*  w ww.  j  ava  2 s  .co  m*/

    // // Am thanh mac dinh
    // try {
    // Uri notification = RingtoneManager
    // .getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    // Ringtone r = RingtoneManager.getRingtone(getApplicationContext(),
    // notification);
    // r.play();
    // } catch (Exception e) {
    // e.printStackTrace();
    // }

    // check app open or close
    if (MainActivity.context != null && MainActivity.state != MainActivity.PAUSE
            && notificationData.getShowPopup().equals("1")) {
        createNotification(context);
    } else {
        generateNotification(context, notificationData);
    }
}

From source file:com.nbplus.vbroadlauncher.BaseActivity.java

public void acquireCpuWakeLock() {
    Log.e(TAG, "Acquiring cpu wake lock");
    if (mCpuWakeLock != null) {
        return;//from  www. j  a  v a 2  s  . c  om
    }

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    mCpuWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "I'm your father");
    mCpuWakeLock.acquire();

    Window window = this.getWindow();
    mDefaultWindowFlags = window.getAttributes().flags;
    window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}

From source file:com.arifin.taxi.penumpang.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from w  w  w . jav  a 2 s  .com*/
private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = new Notification(icon, message, when);

    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    notification = builder.setContentIntent(intent).setSmallIcon(icon).setTicker(message).setWhen(when)
            .setAutoCancel(true).setContentTitle(title).setContentText(message).build();
    // mNM.notify(NOTIFICATION, notification);

    /*notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;*/

    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:org.interactiverobotics.headset_launcher.LauncherService.java

/**
 *    ?./* w w  w.  j ava2 s.  c  o m*/
 *
 */
@SuppressWarnings("deprecation")
private void unlockScreen() {

    final KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

    mKeyguardLock = keyguardManager.newKeyguardLock("HeadsetLauncherLock");

    mKeyguardLock.disableKeyguard();

    final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);

    mWakeLock = powerManager.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "HeadsetLauncherWakeLock");

    mWakeLock.acquire();

    // ?  ?  ?

    mTimeoutHandler.postDelayed(mTimeoutRunnable, Constants.NOTIFICATION_TIMEOUT * 1000);
}

From source file:com.linroid.pushapp.service.DownloadService.java

/**
 * ?/*ww  w. ja va  2  s  .c o  m*/
 * @param pack 
 */
private void onDownloadComplete(Pack pack) {
    Timber.d("%s ?,?:%s", pack.getAppName(), pack.getPath());
    int toastResId = R.string.toast_download_complete;
    if (autoInstall.getValue()) {
        startActivity(IntentUtil.installApk(pack.getPath()));
        if (AndroidUtil.isAccessibilitySettingsOn(this, ApkAutoInstallService.class.getCanonicalName())) {
            PowerManager powermanager = ((PowerManager) getSystemService(Context.POWER_SERVICE));
            PowerManager.WakeLock wakeLock = powermanager.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK
                    | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP),
                    "Install Worker, FULL WAKE LOCK");
            wakeLock.acquire();
            wakeLock.release();
            KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
            //                if(keyguardManager.isDeviceLocked()) {
            final KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("unLock");
            keyguardLock.disableKeyguard();
            //                }
            ApkAutoInstallService.addInstallPackage(pack);
            toastResId = R.string.toast_start_install;
        } else {
            toastResId = R.string.toast_download_complete;
        }
    }
    Toast.makeText(this, getString(toastResId, pack.getAppName()), Toast.LENGTH_SHORT).show();

}

From source file:com.csipsimple.ui.incall.CallActivity.java

@SuppressWarnings("deprecation")
@Override/*  w ww  . ja  v  a  2s .c o  m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //handler.setActivityInstance(this);
    Log.i(TAG, "######## onCreate");
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    this.setFinishOnTouchOutside(false);
    setContentView(R.layout.call_dialog);

    targetName = getIntent().getStringExtra(SipManager.CALLEE_NAME_INTENT_KEY);
    if (targetName != null) {
        Log.i(TAG, "targetName: " + targetName);
    }

    SipCallSession initialSession = getIntent().getParcelableExtra(SipManager.EXTRA_CALL_INFO);
    synchronized (callMutex) {
        callsInfo = new SipCallSession[1];
        callsInfo[0] = initialSession;
    }

    bindService(new Intent(this, SipService.class), connection, Context.BIND_AUTO_CREATE);
    prefsWrapper = new PreferencesProviderWrapper(this);

    // Log.d(TAG, "Creating call handler for " +
    // callInfo.getCallId()+" state "+callInfo.getRemoteContact());
    powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
            | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "com.csipsimple.onIncomingCall");
    wakeLock.setReferenceCounted(false);

    takeKeyEvents(true);

    // Cache findViews
    mainFrame = (ViewGroup) findViewById(R.id.mainFrame);
    //inCallControls = (InCallControls) findViewById(R.id.inCallControls);
    inCallAnswerControls = (InCallAnswerControls) findViewById(R.id.inCallAnswerControls);
    activeCallsGrid = (InCallInfoGrid) findViewById(R.id.activeCallsGrid);
    heldCallsGrid = (InCallInfoGrid) findViewById(R.id.heldCallsGrid);

    // Bind
    attachVideoPreview();

    //inCallControls.setOnTriggerListener(this);
    inCallAnswerControls.setOnTriggerListener(this);

    if (activeCallsAdapter == null) {
        activeCallsAdapter = new CallsAdapter(true);
    }
    activeCallsGrid.setAdapter(activeCallsAdapter);

    if (heldCallsAdapter == null) {
        heldCallsAdapter = new CallsAdapter(false);
    }
    heldCallsGrid.setAdapter(heldCallsAdapter);

    ScreenLocker lockOverlay = (ScreenLocker) findViewById(R.id.lockerOverlay);
    lockOverlay.setActivity(this);
    lockOverlay.setOnLeftRightListener(this);

    /*
    middleAddCall = (Button) findViewById(R.id.add_call_button);
    middleAddCall.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        onTrigger(ADD_CALL, null);
    }
    });
    if (!prefsWrapper.getPreferenceBooleanValue(SipConfigManager.SUPPORT_MULTIPLE_CALLS)) {
    middleAddCall.setEnabled(false);
    middleAddCall.setText(R.string.not_configured_multiple_calls);
    }
    */

    // Listen to media & sip events to update the UI
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_SIP_CALL_CHANGED));
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_SIP_MEDIA_CHANGED));
    registerReceiver(callStateReceiver, new IntentFilter(SipManager.ACTION_ZRTP_SHOW_SAS));

    proximityManager = new CallProximityManager(this, this, lockOverlay);
    keyguardManager = KeyguardWrapper.getKeyguardManager(this);

    dialFeedback = new DialingFeedback(this, true);

    if (prefsWrapper.getPreferenceBooleanValue(SipConfigManager.PREVENT_SCREEN_ROTATION)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    if (quitTimer == null) {
        quitTimer = new Timer("Quit-timer");
    }

    useAutoDetectSpeaker = prefsWrapper.getPreferenceBooleanValue(SipConfigManager.AUTO_DETECT_SPEAKER);

    applyTheme();
    proximityManager.startTracking();

    //inCallControls.setCallState(initialSession);
    inCallAnswerControls.setCallState(initialSession);
}

From source file:com.nanostuffs.yurdriver.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from   w w  w .  ja  v  a 2s. co m*/
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:org.LK8000.LK8000.java

public void initSDL() {
    if (!Loader.loaded)
        return;//w w w  . j  a  va  2  s  .c  om

    /* check if external storage is available; LK8000 doesn't work as
       long as external storage is being forwarded to a PC */
    String state = Environment.getExternalStorageState();
    Log.d(TAG, "getExternalStorageState() = " + state);
    if (!Environment.MEDIA_MOUNTED.equals(state)) {
        TextView tv = new TextView(this);
        tv.setText("External storage is not available (state='" + state + "').  Please turn off USB storage.");
        setContentView(tv);
        return;
    }

    nativeView = new NativeView(this, quitHandler, errorHandler);
    setContentView(nativeView);
    // Receive keyboard events
    nativeView.setFocusableInTouchMode(true);
    nativeView.setFocusable(true);
    nativeView.requestFocus();

    // Obtain an instance of the Android PowerManager class
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    // Create a WakeLock instance to keep the screen from timing out
    final String LKTAG = "LK8000:" + BuildConfig.BUILD_TYPE;
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, LKTAG);

    // Activate the WakeLock
    wakeLock.acquire();
}

From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.ColorimetryLiquidActivity.java

/**
 * Acquire a wake lock to prevent the screen from turning off during the analysis process.
 *///from www  . ja v a2  s .co m
private void acquireWakeLock() {
    if (wakeLock == null || !wakeLock.isHeld()) {
        PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
        //noinspection deprecation
        wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "CameraSensorWakeLock");
        wakeLock.acquire();
    }
}