Java Code Examples for android.content.Intent.ACTION_SCREEN_OFF

The following are Jave code examples for showing how to use ACTION_SCREEN_OFF of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PrivacyStreams   File: DeviceEventUpdatesProvider.java   View Source Code Vote up 9 votes
@Override
public void onReceive(Context context, Intent intent) {
    String event = null;
    String type = null;

    switch(intent.getAction()){
        case Intent.ACTION_SCREEN_OFF:
            event = DeviceEvent.EVENT_SCREEN_OFF;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_SCREEN_ON:
            event = DeviceEvent.EVENT_SCREEN_ON;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_USER_PRESENT:
            event = DeviceEvent.EVENT_SCREEN_USER_PRESENT;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_BOOT_COMPLETED:
            event = DeviceEvent.EVENT_BOOT_COMPLETED;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_SHUTDOWN:
            event = DeviceEvent.EVENT_BOOT_SHUTDOWN;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_BATTERY_LOW:
            event = DeviceEvent.EVENT_BATTERY_LOW;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_BATTERY_OKAY:
            event = DeviceEvent.EVENT_BATTERY_OKAY;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_CONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_DISCONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case AudioManager.RINGER_MODE_CHANGED_ACTION:
            AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
            switch (am.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    event = DeviceEvent.EVENT_RINGER_SILENT;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_VIBRATE:
                    event = DeviceEvent.EVENT_RINGER_VIBRATE;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_NORMAL:
                    event = DeviceEvent.EVENT_RINGER_NORMAL;
                    type = DeviceEvent.TYPE_RINGER;
                    break;
            }
        default:
            break;
    }

    if (type != null)
        output(new DeviceEvent(type, event));
}
 
Example 2
Project: Xndroid   File: XndroidReceiver.java   View Source Code Vote up 9 votes
@Override
public void onReceive(Context context, Intent intent) {
    try {
        String action = intent.getAction();
        if(action == Intent.ACTION_BATTERY_CHANGED){
            handleBattery(intent);
        }else if(action == ConnectivityManager.CONNECTIVITY_ACTION){
            AppModel.getNetworkState();
        }else if(action == Intent.ACTION_SCREEN_ON){
            AppModel.sDevScreenOff = false;
            LogUtils.i("screen on");
        }else if(action == Intent.ACTION_SCREEN_OFF){
            AppModel.sDevScreenOff = true;
            LogUtils.i("screen off");
        }
    }catch (Exception e){
        LogUtils.e("onReceive error ", e);
    }

}
 
Example 3
Project: SmingZZick_App   File: ScreenCaptureService.java   View Source Code Vote up 7 votes
@Override
protected boolean handleBraodcast(Context context, Intent intent) {
    String action = intent.getAction();
    switch (action) {
        case Intent.ACTION_SCREEN_OFF:
            isScreenOff = true;
            stopSming();
            return true;
        case Intent.ACTION_SCREEN_ON:
            isScreenOff = false;
            return true;
    }
    return false;
}
 
Example 4
Project: android-util2   File: ReceiverHelper.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, String action, Intent intent) {
    switch (action){
        case Intent.ACTION_SCREEN_OFF:
            onScreenOff(context);
            break;
        case Intent.ACTION_SCREEN_ON:
            onScreenOn(context);
            break;
        default:
            onReceiveOthers(context, action, intent);
    }
}
 
Example 5
Project: pracler   File: LockScreenService.java   View Source Code Vote up 6 votes
@Override
public void onCreate() {
    super.onCreate();
    global = (Global) getApplication();
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(receiver, filter);
}
 
Example 6
Project: AssistantBySDK   File: AssistantService.java   View Source Code Vote up 6 votes
public void registerReveicer() {
    registerReceiver(netWorkChangeReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    IntentFilter inf = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    inf.addAction(Intent.ACTION_SCREEN_ON);
    registerReceiver(scrennReceiver, inf);
    registerReceiver(headSetInReceiver, new IntentFilter("android.intent.action.HEADSET_PLUG"));
    IntentFilter bit = new IntentFilter(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
    // bit.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
    //bit.addAction(BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT);
    registerReceiver(blueConnectStateBroadcastReceiver, bit);
    IntentFilter smsFilter = new IntentFilter(SMS_RECEIVED_ACTION);
    smsFilter.setPriority(2147483647);
    smsFilter.addAction(GSM_SMS_RECEIVED_ACTION);
    registerReceiver(smsReceiver, smsFilter);
}
 
Example 7
Project: PingWidget   File: PingWidgetUpdateService.java   View Source Code Vote up 6 votes
@Override
public void onCreate() {
    Log.d(TAG, "onCreate()");
    super.onCreate();

    //Register ScreenReceiver to screen on/off broadcasts
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    //filter.addAction(Intent.ACTION_SCREEN_ON);
    BroadcastReceiver mReceiver = new ScreenReceiver();
    registerReceiver(mReceiver, filter);
}
 
Example 8
Project: LockScreen-Oreo   File: LockScreenService.java   View Source Code Vote up 6 votes
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);
    receiver = new LockScreenReceiver();
    registerReceiver(receiver, filter);
//    startForeground();
    return START_STICKY;

}
 
Example 9
Project: RetroMusicPlayer   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action != null) {
        switch (action) {
            case Intent.ACTION_SCREEN_OFF:
                collapsePanel();
                if (PreferenceUtil.getInstance(context).getLockScreen() && MusicPlayerRemote.isPlaying()) {
                    context.startActivity(new Intent(context, LockScreenActivity.class));
                }
                break;
        }
    }
}
 
Example 10
Project: nirbhaya   File: PhoneLocatorService.java   View Source Code Vote up 5 votes
@Override
public void onCreate() {
    super.onCreate();
    //setting up the broadcast

    am = (AudioManager)(getApplicationContext().getSystemService(Context.AUDIO_SERVICE));
    mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.siren);
    mediaPlayer.setLooping(true);

    sensorManager = (SensorManager)getSystemService(getApplicationContext().SENSOR_SERVICE);
    sensorAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

    sensorManager.registerListener(this, sensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);

    mBroadcastReceiver = new SMSBroadcastReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction("android.provider.Telephony.SMS_RECEIVED");
    registerReceiver(mBroadcastReceiver, filter);


    IntentFilter newFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
    registerReceiver(mReceiver, newFilter);


    PowerManager manager =
            (PowerManager) getSystemService(Context.POWER_SERVICE);
    mWakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, PhoneLocatorService.class.getName());

    // Create a notification area notification so the user
    // can get back to the PhoneLocator Service and Close It

    final Intent notificationIntent = new Intent(getApplicationContext(),
            NirbhayaActivity.class);
    final PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    final Notification notification = new Notification.Builder(
            getApplicationContext())
            .setSmallIcon(R.drawable.ic_launcher)
            .setOngoing(true).setContentTitle("Nirbhaya")
            .setContentText("Click to Access Nirbhaya Service")
            .setContentIntent(pendingIntent).build();

    // Put this Service in a foreground state, so it won't
    // readily be killed by the system
    startForeground(NOTIFICATION_ID, notification);

    firstTimeAlert = false;
    mLocationSendServiceIntent = new Intent(NirbhayaActivity.getMainApp(), LocationSendService.class);
}