Example usage for android.os PowerManager newWakeLock

List of usage examples for android.os PowerManager newWakeLock

Introduction

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

Prototype

public WakeLock newWakeLock(int levelAndFlags, String tag) 

Source Link

Document

Creates a new wake lock with the specified level and flags.

Usage

From source file:info.balthaus.geologrenewed.app.service.BackgroundService.java

@SuppressLint("NewApi")
@Override/*from   w  w w. j a v  a2 s. c  o  m*/
public void onCreate() {
    super.onCreate();
    Debug.log("Service created");

    if (thread == null) {
        Debug.log("Launching thread");
        thread = new ServiceThread();
        thread.setContext(getApplicationContext());
        thread.start();
    }

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    wakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "GeoLog Wakelock");

    Intent i = new Intent();
    i.setAction(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setClass(this, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent = PendingIntent.getActivity(this, 0, i, 0);

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = (new Notification.Builder(this)).setSmallIcon(R.drawable.ic_stat_service)
            .setContentIntent(notificationIntent).setWhen(System.currentTimeMillis()).setAutoCancel(false)
            .setOngoing(true).setContentTitle(getString(R.string.service_title))
            .setContentText(getString(R.string.service_waiting));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        notificationBuilder.setShowWhen(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        /* quick turn off, maybe ? if added, make sure to add a button to preferences to disable these buttons
        notificationBuilder.
        setPriority(Notification.PRIORITY_MAX).
        addAction(0, "A", notificationIntent).
        addAction(0, "B", notificationIntent).
        addAction(0, "C", notificationIntent);
        */
    }

    updateNotification();
}

From source file:com.example.activitydemo.app.service.GameService.java

public void startGame(final GameConfig config) {
    // Start ourselves!
    startService(new Intent(this, GameService.class));

    synchronized (mBinderService) {
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        if (mWakeLock == null) {
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ActivityGameService");
            mWakeLock.setReferenceCounted(false);
        }/*from ww  w .ja v a 2s  .  co  m*/

        mWakeLock.acquire();
    }

    mTextToSpeechEnabled = config.useSound;

    Log.d(TAG, "Starting game!");
    sayString(getString(R.string.game_started));
    setGameCallbacks(new GameLogic(this, config, GameTrack.BASIC_TRACK));

    startForeground();
    registerActivityUpdates();
    mGameHandler.startGame();

    if (mBinderService.isConnected()) {
        try {
            mBinderService.mCallbacks.onStartGame();
        } catch (RemoteException e) {
        }
    }
}

From source file:com.example.damerap_ver1.IntroVideoActivity.java

@Override
protected void onCreate(Bundle pSavedInstanceState) {
    super.onCreate(pSavedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // create the layout of the view
    setupView();/*from w  w  w. ja v a  2  s  .  c  o m*/

    // determine the messages to be displayed as the view loads the video
    extractMessages();

    // grab a wake-lock so that the video can play without the screen being turned off
    PowerManager lPwrMgr = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = lPwrMgr.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG_WAKELOCK);
    mWakeLock.acquire();

    mProgressMessage.setText(mMsgInit);

    // extract the playlist or video id from the intent that started this video

    Uri lVideoIdUri = this.getIntent().getData();

    if (lVideoIdUri == null) {
        Log.i(this.getClass().getSimpleName(),
                "No video ID was specified in the intent.  Closing video activity.");
        finish();
    }
    String lVideoSchemeStr = lVideoIdUri.getScheme();
    String lVideoIdStr = lVideoIdUri.getEncodedSchemeSpecificPart();
    if (lVideoIdStr == null) {
        Log.i(this.getClass().getSimpleName(),
                "No video ID was specified in the intent.  Closing video activity.");
        finish();
    }
    if (lVideoIdStr.startsWith("//")) {
        if (lVideoIdStr.length() > 2) {
            lVideoIdStr = lVideoIdStr.substring(2);
        } else {
            Log.i(this.getClass().getSimpleName(),
                    "No video ID was specified in the intent.  Closing video activity.");
            finish();
        }
    }

    ///////////////////
    // extract either a video id or a playlist id, depending on the uri scheme
    YouTubeId lYouTubeId = null;
    if (lVideoSchemeStr != null && lVideoSchemeStr.equalsIgnoreCase(SCHEME_YOUTUBE_PLAYLIST)) {
        lYouTubeId = new PlaylistId(lVideoIdStr);
    }

    else if (lVideoSchemeStr != null && lVideoSchemeStr.equalsIgnoreCase(SCHEME_YOUTUBE_VIDEO)) {
        lYouTubeId = new VideoId(lVideoIdStr);
    }

    if (lYouTubeId == null) {
        Log.i(this.getClass().getSimpleName(),
                "Unable to extract video ID from the intent.  Closing video activity.");
        finish();
    }

    mQueryYouTubeTask = (QueryYouTubeTask) new QueryYouTubeTask().execute(lYouTubeId);
}

From source file:com.wirelessmoves.cl.MainActivity.java

@SuppressWarnings("deprecation")
@Override//from w w w  . j  a v a 2  s . co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /* If saved variable state exists from last run, recover it */
    if (savedInstanceState != null) {
        NumberOfSignalStrengthUpdates = savedInstanceState.getLong("NumberOfSignalStrengthUpdates");

        LastCellId = savedInstanceState.getLong("LastCellId");
        NumberOfCellChanges = savedInstanceState.getLong("NumberOfCellChanges");

        LastLacId = savedInstanceState.getLong("LastLacId");
        NumberOfLacChanges = savedInstanceState.getLong("NumberOfLacChanges");

        PreviousCells = savedInstanceState.getLongArray("PreviousCells");
        PreviousCellsIndex = savedInstanceState.getInt("PreviousCellsIndex");
        NumberOfUniqueCellChanges = savedInstanceState.getLong("NumberOfUniqueCellChanges");

        outputDebugInfo = savedInstanceState.getBoolean("outputDebugInfo");

        CurrentLocationLong = savedInstanceState.getDouble("CurrentLocationLong");
        CurrentLocationLat = savedInstanceState.getDouble("CurrentLocationLat");

        /* attempt to restore the previous gps location information object */
        PrevLocation = (Location) getLastNonConfigurationInstance();

    } else {
        /* Initialize PreviousCells Array to defined values */
        for (int x = 0; x < PreviousCells.length; x++)
            PreviousCells[x] = 0;
    }

    /* Get a handle to the telephony manager service */
    /* A listener will be installed in the object from the onResume() method */
    MyListener = new MyPhoneStateListener();
    Tel = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    /* get a handle to the power manager and set a wake lock so the screen saver
     * is not activated after a timeout */
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");

    /* Get a handle to the location system for getting GPS information */
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    gpsListener = new myLocationListener();
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsListener);

}

From source file:biz.bokhorst.bpt.BPTService.java

@Override
public IBinder onBind(Intent intent) {
    // Start foreground service
    startForeground(1, getNotification(getString(R.string.Running)));

    // Instantiate helpers
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    databaseHelper = new DatabaseHelper(this);
    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    taskHandler = new Handler();
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BPT");
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    Intent alarmIntent = new Intent("BPT_ALARM");
    pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmReceiver = new BPTAlarmReceiver();
    registerReceiver(alarmReceiver, new IntentFilter("BPT_ALARM"));

    bound = true;/*w  w w .  j a  va 2s.  c om*/
    return serverMessenger.getBinder();
}

From source file:com.achow101.bitcointalkforum.NotificationService.java

private void handleIntent(Intent intent) {
    // obtain the wake lock
    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NotificationService");
    mWakeLock.acquire();/*from  ww  w . j  a v  a2  s  . c  o  m*/

    // get sessid and username from intent
    String sessId = intent.getStringExtra("SESSION ID");
    String mUsername = intent.getStringExtra("Username");

    // check the global background data setting
    ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    if (!cm.getBackgroundDataSetting()) {
        stopSelf();
        return;
    }

    // Get preferences
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    // Check that notifications are wanted
    boolean getNotifs = prefs.getBoolean("notifications_new_message", true);

    // do stuff if notifications are wanted
    if (getNotifs) {
        // get remaining booleans
        boolean getWatchlist = prefs.getBoolean("notifications_watchlist", true);
        boolean getUnreadposts = prefs.getBoolean("notifications_unreadposts", false);
        boolean getUnreadreplies = prefs.getBoolean("notifications_unreadreplies", false);
        boolean getMessages = prefs.getBoolean("notifications_messages", true);

        // Get notification settings stuff
        sound = prefs.getString("notifications_new_message_ringtone",
                "content://settings/system/notification_sound");
        vibrate = prefs.getBoolean("notifications_new_message_vibrate", true);

        // do the actual work, in a separate thread
        new PollTask(getWatchlist, getUnreadposts, getUnreadreplies, getMessages, sessId, mUsername).execute();
    }
}

From source file:org.kde.necessitas.ministro.MinistroActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*from  w  w  w.j  a v  a  2  s .c  o  m*/
    m_qtLibsRootPath = getFilesDir().getAbsolutePath() + "/qt/";
    File dir = new File(m_qtLibsRootPath);
    dir.mkdirs();
    nativeChmode(m_qtLibsRootPath, 0755);
    bindService(new Intent("org.kde.necessitas.ministro.IMinistro"), m_ministroConnection,
            Context.BIND_AUTO_CREATE);
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    m_wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Ministro");
    m_wakeLock.acquire();
}

From source file:com.thadeus.youtube.IntroVideoActivity.java

@Override
protected void onCreate(Bundle pSavedInstanceState) {
    super.onCreate(pSavedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    // create the layout of the view
    setupView();//from  w  w w  .j  a va 2s.  c  o  m

    // determine the messages to be displayed as the view loads the video
    extractMessages();

    // grab a wake-lock so that the video can play without the screen being turned off
    PowerManager lPwrMgr = (PowerManager) getSystemService(POWER_SERVICE);
    mWakeLock = lPwrMgr.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG_WAKELOCK);
    mWakeLock.acquire();

    mProgressMessage.setText(mMsgInit);

    // extract the playlist or video id from the intent that started this video

    Uri lVideoIdUri = this.getIntent().getData();
    mVideoURI = lVideoIdUri;

    //        if(lVideoIdUri == null){
    //            Log.i(this.getClass().getSimpleName(), "No video ID was specified in the intent.  Closing video activity.");
    //            finish();
    //        }
    //        String lVideoSchemeStr = lVideoIdUri.getScheme();
    //        String lVideoIdStr     = lVideoIdUri.getEncodedSchemeSpecificPart();
    //        if(lVideoIdStr == null){
    //            Log.i(this.getClass().getSimpleName(), "No video ID was specified in the intent.  Closing video activity.");
    //            finish();
    //        }
    //        if(lVideoIdStr.startsWith("//")){
    //            if(lVideoIdStr.length() > 2){
    //                lVideoIdStr = lVideoIdStr.substring(2);
    //            } else {
    //                Log.i(this.getClass().getSimpleName(), "No video ID was specified in the intent.  Closing video activity.");
    //                finish();
    //            }
    //        }

    ///////////////////
    // extract either a video id or a playlist id, depending on the uri scheme
    //        YouTubeId lYouTubeId = null;
    //        if(lVideoSchemeStr != null && lVideoSchemeStr.equalsIgnoreCase(SCHEME_YOUTUBE_PLAYLIST)){
    //            lYouTubeId = new PlaylistId(lVideoIdStr);
    //        }
    //
    //        else if(lVideoSchemeStr != null && lVideoSchemeStr.equalsIgnoreCase(SCHEME_YOUTUBE_VIDEO)){
    //            lYouTubeId = new VideoId(lVideoIdStr);
    //        }
    //
    //        if(lYouTubeId == null){
    //            Log.i(this.getClass().getSimpleName(), "Unable to extract video ID from the intent.  Closing video activity.");
    //            finish();
    //        }
    playVideo(mVideoURI);
    //mQueryYouTubeTask = (QueryYouTubeTask) new QueryYouTubeTask().execute(lYouTubeId);
}

From source file:com.oo58.game.texaspoker.AppActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //         this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED, FLAG_HOMEKEY_DISPATCHED);//
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    mContext = AppActivity.this;

    try {//  w  ww .j a  v  a2 s . c o  m
        ApplicationInfo appInfo = this.getPackageManager().getApplicationInfo(getPackageName(),
                PackageManager.GET_META_DATA);
        String msg = appInfo.metaData.getString("data_Name");

        //         int channelid = Integer.parseInt(msg) ;
        //         
        //         System.out.println(channelid);

    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    mAct = this;
    allContext = this.getApplicationContext();
    mTencent = Tencent.createInstance("1104823392", getApplicationContext());
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "MyLock");
    mWakeLock.acquire();

    MobclickAgent.setDebugMode(false);
    MobclickAgent.updateOnlineConfig(this);
    AnalyticsConfig.enableEncrypt(true);

    checkUpdate();

    PackageManager pm2 = getPackageManager();
    homeInfo = pm2.resolveActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME), 0);

    mNetChecker.initAndRegListener(mContext);

    mWXPay.init(this);

    MobClickCppHelper.init(this);

    //      // logcatdebug
    //       XGPushConfig.enableDebug(this, true);
    //      // registerPush(getApplicationContext(), XGIOperateCallback)callback
    //      // registerPush(getApplicationContext(),account)
    //      // 
    //      // ApplicationContext
    //      Context context = getApplicationContext();
    //      XGPushManager.registerPush(context);    
    //       
    //      // 2.362
    //      Intent service = new Intent(context, XGPushService.class);
    //      context.startService(service);

    // API
    // registerPush(context,account)registerPush(context,account, XGIOperateCallback)accountAPPqqopenid
    // registerPush(context,"*")account="*"
    // unregisterPush(context)
    // setTag(context, tagName)
    // deleteTag(context, tagName)

    updateListViewReceiver = new MsgReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction("com.oo58.game.texaspoker.activity.UPDATE_LISTVIEW");
    registerReceiver(updateListViewReceiver, intentFilter);

    XGPushManager.registerPush(getApplicationContext(), new XGIOperateCallback() {
        @Override
        public void onSuccess(Object data, int flag) {
            //                  Log.w(Constants.LogTag,
            //                        "+++ register push sucess. token:" + data);

        }

        @Override
        public void onFail(Object data, int errCode, String msg) {
            //                  Log.w(Constants.LogTag,
            //                        "+++ register push fail. token:" + data
            //                              + ", errCode:" + errCode + ",msg:"
            //                              + msg);

        }
    });

    //javajosnC++demo
    /*      JSONObject jsonObj = new JSONObject();  
            try {
             jsonObj.put("Int_att",25);
               jsonObj.put("String_att","str");//string  
               jsonObj.put("Double_att",12.25);//double  
               jsonObj.put("Boolean_att",true);//boolean  
          } catch (JSONException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
          }//int  
            
            PushJson(jsonObj.toString()) ;*/

}