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.cellbots.eyes.EyesActivity.java

/** Called when the activity is first created. */
@Override//from  w  w w.j  a  v  a  2  s  .c  o  m
public void onCreate(Bundle savedInstanceState) {
    Log.e("remote eyes", "started");
    super.onCreate(savedInstanceState);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "Cellbot Eyes");
    mWakeLock.acquire();

    mTorchMode = false;

    out = new ByteArrayOutputStream();

    if ((getIntent() != null) && (getIntent().getData() != null)) {
        putUrl = getIntent().getData().toString();
        server = putUrl.replace("http://", "");
        server = server.substring(0, server.indexOf("/"));
        Bundle extras = getIntent().getExtras();
        if ((extras != null) && (extras.getBoolean("TORCH", false))) {
            mTorchMode = true;
        }
    } else {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        putUrl = prefs.getString("REMOTE_EYES_PUT_URL", "");
        Log.e("prefs", putUrl);
        if (putUrl.length() < 1) {
            Intent i = new Intent();
            i.setClass(this, PrefsActivity.class);
            startActivity(i);
            finish();
            return;
        } else {
            server = putUrl.replace("http://", "");
            server = server.substring(0, server.indexOf("/"));
        }
    }

    resetConnection();
    mHttpState = new HttpState();

    setContentView(R.layout.eyes_main);
    mPreview = (SurfaceView) findViewById(R.id.eyes_preview);
    mHolder = mPreview.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    mPreview.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            setTorchMode(!mTorchMode);
        }
    });

    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean useTorch = intent.getBooleanExtra("TORCH", false);
            boolean shouldTakePicture = intent.getBooleanExtra("PICTURE", false);
            setTorchMode(useTorch);
            setTakePicture(shouldTakePicture);
        }
    };

    this.registerReceiver(mReceiver, new IntentFilter(EyesActivity.EYES_COMMAND));

    mFrame = (FrameLayout) findViewById(R.id.eyes_frame);
    mWebView = new WebView(this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    // Use this if you want to load content locally
    // mWebView.loadUrl("content://com.cellbot.localpersonas/default/index.html");
    mWebView.loadUrl("http://personabots.appspot.com/expressions/tuby");

    mFrame.addView(mWebView);
}

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///  w  ww.  ja va2s  .  c  o m
public static 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:it.technocontrolsystem.hypercontrol.gcm.HCGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *//*from  ww w . j a va  2s  .c om*/
private void sendNotification(Bundle data) {
    String messagetype = data.getString("messagetype");

    switch (messagetype) {

    // crea una notifica che quando cliccata apre il site in allarme
    case "alarm":

        String siteUUID = data.getString("sitenum");
        Site site = DB.getSiteByUUID(siteUUID);

        if (site != null) {

            Intent intent = new Intent();
            intent.setClass(this, SiteActivity.class);
            intent.putExtra("siteid", site.getId());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                    PendingIntent.FLAG_ONE_SHOT);

            String title = "Allarme";
            title += " " + site.getName();

            //                String msg = "";
            //                try {
            //                    int plantnum = Integer.parseInt(data.getString("plantnum"));
            //                    Plant plant = DB.getPlantBySiteAndNumber(siteid, plantnum);
            //                    msg += plant.getName();
            //
            //                    int areanum = Integer.parseInt(data.getString("areanum"));
            //                    Area area = DB.getAreaByIdPlantAndAreaNumber(plant.getId(), areanum);
            //                    msg += " " + area.getName();
            //
            //                } catch (Exception e) {
            //                }

            String msg = data.getString("message");
            Uri defaultSoundUri = Lib.resourceToUri(R.raw.siren);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(msg)
                    .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

            Notification mNotification = notificationBuilder.build();
            mNotification.flags |= Notification.FLAG_INSISTENT;

            NotificationManager notificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);

            notificationManager.notify(0, mNotification);

        } else {
            Log.e(TAG, "site uuid " + siteUUID + " not found");
        }

        break;

    // crea una notifica informativa
    case "info":

        // qui creare la notifica
        // ...

        break;

    }

    // dopo la notifica sveglia il device
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            (PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), getClass().getSimpleName());
    wakeLock.acquire();

}

From source file:csic.ceab.movelab.beepath.FixGet.java

/**
 * Creates a new FixGet service instance.<br>
 * Begins location recording process. Creates a location manager and two
 * location listeners. Begins requesting updates from both the GPS and
 * network services, with one location listener receiving updates from one
 * provider./*from   www .jav a  2 s.  c  o  m*/
 * <p>
 * If either provider is unavailable, no updates will ever be returned to
 * the corresponding location listener.
 */

@Override
public void onCreate() {

    Context context = getApplicationContext();

    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).createWifiLock(
            WifiManager.WIFI_MODE_SCAN_ONLY,
            context.getResources().getString(R.string.internal_message_id) + "WifiLock");

    wakeLock = ((PowerManager) context.getSystemService(Context.POWER_SERVICE)).newWakeLock(
            PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            context.getResources().getString(R.string.internal_message_id) + "ScreenDimWakeLock");

    minDist = Util.getMinDist(context);

}

From source file:com.example.isaac.nileswestlitcenter.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from w  w w. j  a  v  a  2  s . c o m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {

        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {

            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            // This loop represents the service doing some work.

        }
        if (extras.getString("subject") != null) {
            if (intent.getExtras().getString("delete") != null) {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    //delete from arraylist
                    for (int i = 0; i < storeWhileScreenOff.size(); i++) {
                        if (storeWhileScreenOff.get(i)[1] == extras.getString("subject")
                                && storeWhileScreenOff.get(i)[2] == extras.getString("name")) {
                            storeWhileScreenOff.remove(i);
                            return;
                        }
                    }
                    //not in stored list, but on screen
                    storeWhileScreenOff.add(
                            new String[] { "true", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(true, extras.getString("subject"), extras.getString("name"));
                    //                    MainActivity.deleteStudentFromList(extras.getString("subject"),extras.getString("name"));
                    //                   or MainActivity.delete(extras.getInt("id"));
                }
            } else {
                if (((KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE))
                        .inKeyguardRestrictedInputMode()) {
                    storeWhileScreenOff.add(
                            new String[] { "false", extras.getString("subject"), extras.getString("name") });
                } else {
                    sendMessage(false, extras.getString("subject"), extras.getString("name"));
                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
                // Post notification of received message.
                sendNotification(extras.getString("subject"), extras.getString("name"));
                Vibrator v = (Vibrator) this.getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
                // Vibrate for 500 milliseconds
                v.vibrate(1000);
                ((PowerManager) getSystemService(POWER_SERVICE))
                        .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
                                "TAG")
                        .acquire();
                Log.i(TAG, "Received: " + extras.toString());

            }

        }
    }

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateAcceptfriendNotification(Context context, String message, String status) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    if (status.equalsIgnoreCase("accept"))
        message = message + " added you as buddy";
    else//  w w  w .  j  a  va  2 s  . c o m
        message = message + " rejected you as buddy";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}

From source file:ti.modules.titanium.android.notificationmanager.NotificationManagerModule.java

@Kroll.method
public void notify(int id, Object notificationValue) {
    NotificationProxy notificationProxy = NotificationProxy.fromObject(notificationValue);
    NotificationManager manager = getManager();
    if (manager != null && notificationProxy != null) {
        // targeting Android O or above? create default channel

        try {//from w  w  w.  j  a  v a 2 s .co m
            notificationProxy.setCurrentId(id);
            Notification notification = notificationProxy.getNotification();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                    && notification.getChannelId() == DEFAULT_CHANNEL_ID) {
                useDefaultChannel();
            }
            getManager().notify(id, notification);
            HashMap wakeParams = notificationProxy.getWakeParams();
            if (wakeParams != null) {
                int wakeTime = TiConvert.toInt(wakeParams.get("time"), 3000);
                int wakeFlags = TiConvert.toInt(wakeParams.get("flags"), (PowerManager.FULL_WAKE_LOCK
                        | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE));
                PowerManager pm = (PowerManager) TiApplication.getInstance()
                        .getSystemService(TiApplication.getInstance().getApplicationContext().POWER_SERVICE);
                if (pm != null && !pm.isScreenOn()) {
                    try {
                        WakeLock wl = pm.newWakeLock(wakeFlags, "TiWakeLock");
                        wl.acquire(wakeTime);
                    } catch (IllegalArgumentException e) {
                        Log.e(TAG, e.getMessage());
                    }
                }
            }
        } catch (Exception e) {

        }
    }
}

From source file:org.simlar.SimlarService.java

@Override
public void onCreate() {
    Log.i(LOGTAG, "started on device: " + Build.DEVICE);

    FileHelper.init(this);
    mVibratorThread = new VibratorThread(this.getApplicationContext());
    mRingtoneThread = new RingtoneThread(this.getApplicationContext());

    mWakeLock = ((PowerManager) this.getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "SimlarWakeLock");
    mWifiLock = ((WifiManager) this.getSystemService(Context.WIFI_SERVICE))
            .createWifiLock(WifiManager.WIFI_MODE_FULL, "SimlarWifiLock");

    startForeground(NOTIFICATION_ID, createNotification(SimlarStatus.OFFLINE));

    mLinphoneThread = new LinphoneThread(this, this);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mNetworkChangeReceiver, intentFilter);

    startKeepAwake();//  w ww  .j a va 2 s . co  m

    mHandler.post(new Runnable() {
        @Override
        public void run() {
            initializeCredentials();
        }
    });
}

From source file:org.xwalk.app.template.AppTemplateActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // fullscreen immersive mode
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    // super user
    try {/*from   w  w  w.  j  a v a  2  s  .co m*/
        Process p = Runtime.getRuntime().exec("su");
    } catch (IOException e) {
        e.printStackTrace();
    }

    JSONObject obj = UCCIO.read(UCCIO.ConfigFile.SYSTEM);
    if (obj != null) {

        try {

            apk_updater_server = obj.getString("apk_updater_server");
            apk_updater_server_port = obj.getString("apk_updater_server_port");
            apk_updater_path = obj.getString("apk_updater_path");
            apk_update_on_boot = obj.getBoolean("apk_update_on_boot");
            str_apk_update_interval = obj.getString("apk_update_interval");

            String[] str_a_apk_update_interval = str_apk_update_interval.split(":");
            if (str_a_apk_update_interval != null && str_a_apk_update_interval.length == 2) {
                int i = Integer.parseInt(str_a_apk_update_interval[0]);
                String k = str_a_apk_update_interval[1];

                Log.d(TAG, "apk update interval: " + i + ":" + k);

                if (k.equalsIgnoreCase("M"))
                    apk_update_interval = i * AutoUpdateApk.MINUTES;
                else if (k.equalsIgnoreCase("H"))
                    apk_update_interval = i * AutoUpdateApk.HOURS;
                else if (k.equalsIgnoreCase("D"))
                    apk_update_interval = i * AutoUpdateApk.DAYS;
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        try {
            str_wakeup_rtc_time = obj.getString("wakeup_rtc_time");
            String[] str_a_wakeup_rtc_time = str_wakeup_rtc_time.split(":");
            if (str_a_wakeup_rtc_time != null && str_a_wakeup_rtc_time.length == 2) {
                wakeup_rtc_time_hours = Integer.parseInt(str_a_wakeup_rtc_time[0]);
                wakeup_rtc_time_minutes = Integer.parseInt(str_a_wakeup_rtc_time[1]);
            }

            str_sleep_rtc_time = obj.getString("sleep_rtc_time");
            String[] str_a_sleep_rtc_time = str_sleep_rtc_time.split(":");
            if (str_a_sleep_rtc_time != null && str_a_sleep_rtc_time.length == 2) {
                sleep_rtc_time_hours = Integer.parseInt(str_a_sleep_rtc_time[0]);
                sleep_rtc_time_minutes = Integer.parseInt(str_a_sleep_rtc_time[1]);
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    if (apk_updater_server_port != null && !apk_updater_server_port.isEmpty())
        apk_updater_server = apk_updater_server + ":" + apk_updater_server_port;

    Log.i(TAG, "apk server: " + apk_updater_server);
    Log.i(TAG, "apk server path: " + apk_updater_path);
    Log.i(TAG, "apk update interval (ms): " + apk_update_interval);

    sau = new SilentAutoUpdate(getApplicationContext(), apk_updater_path, apk_updater_server);
    sau.addObserver(this);

    if (apk_update_on_boot)
        sau.checkUpdatesManually();

    sau.setUpdateInterval(apk_update_interval);

    // WAKEUP / SLEEP

    pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    UCCLauncherReceiver.wl = pm
            .newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);

    Log.i(TAG, "sleep time: " + sleep_rtc_time_hours + ":" + sleep_rtc_time_minutes);
    Log.i(TAG, "wakeup time: " + wakeup_rtc_time_hours + ":" + wakeup_rtc_time_minutes);

    set_RTC_sleep((Context) this);
    set_RTC_wakeup((Context) this);

    if (!UCCLauncherReceiver.wl.isHeld())
        UCCLauncherReceiver.wl.acquire();

}

From source file:com.automated.taxinow.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///w w  w .j  a v  a2 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);
    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();
}