Java Code Examples for android.content.Intent.ACTION_SCREEN_ON

The following are Jave code examples for showing how to use ACTION_SCREEN_ON 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: PrivacyStreams   File: DeviceEventUpdatesProvider.java   View Source Code Vote up 7 votes
@Override
protected void provide() {
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_USER_PRESENT);

    filter.addAction(Intent.ACTION_SHUTDOWN);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);
    filter.addAction(Intent.ACTION_BATTERY_LOW);
    filter.addAction(Intent.ACTION_BATTERY_OKAY);
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);

    mReceiver = new DeviceStateReceiver();
    getContext().registerReceiver(mReceiver, filter);
}
 
Example 4
Project: QuranAndroid   File: AudioService.java   View Source Code Vote up 7 votes
@Override
public void onCreate() {
    super.onCreate();

    //media player intents
    IntentFilter mediaPlayerFilter = new IntentFilter();
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.PLAY);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.PAUSE);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.BACK);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.FORWARD);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.STOP);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.REPEAT_ON);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.REPEAT_OFF);
    registerReceiver(MediaPlayerBroadcast, mediaPlayerFilter);

    //screen on / of guard key unlock flag
    IntentFilter screenIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    screenIntentFilter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(MediaPlayerNotificationShow, screenIntentFilter);

}
 
Example 5
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 6
Project: DoorAccess   File: LocationService.java   View Source Code Vote up 7 votes
@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "onCreate");

    initLocationManager();

    /*  DB service before listen the event */
    mDBService = DBService.getInstance(getApplicationContext());
    mULRDao = mDBService.getUIDLocationRelationDao();
    mTagDao = mDBService.getTagDao();
    mRLDao = mDBService.getReaderLocationDao();

    DaemonConfiguration.Init(getApplicationContext());
    mDaemon = DaemonConfiguration.getInstance();

    IntentFilter screenOn = new IntentFilter(Intent.ACTION_SCREEN_ON);
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i(TAG, "screen on");
            requestLocation();
        }
    }, screenOn);
}
 
Example 7
Project: InitialVolume   File: Service.java   View Source Code Vote up 7 votes
@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences prefs;
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
            IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
            context.getApplicationContext().registerReceiver(this, filter);
            prefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (prefs.getBoolean(context.getString(R.string.pref_set_on_boot), false)) {
                setVolume(context);
            }
            break;
        case Intent.ACTION_SCREEN_ON:
            prefs = PreferenceManager.getDefaultSharedPreferences(context);
            if (prefs.getBoolean(context.getString(R.string.pref_set_on_screen_on), false)) {
                setVolume(context);
            }
            break;
    }
}
 
Example 8
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 9
Project: BlueBolt-Kernel-Tweaking-app   File: ProximityService.java   View Source Code Vote up 6 votes
@Override
public void onCreate(){
    if(DEBUG) Log.i(TAG,"Service Started");
    proximitySensorDetails = new ProximitySensorDetails(this);

    IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(screenStateReceiver, screenStateFilter);

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL, "BlueBolt Pocket Mode", NotificationManager.IMPORTANCE_UNSPECIFIED);
        notificationManager.createNotificationChannel(notificationChannel);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, SplashActivity.class), 0);

        Notification.Builder builder = new Notification.Builder(this, CHANNEL);
        builder.setContentTitle(notificationTitle)
                .setContentText(notificationText)
                .setSmallIcon(R.mipmap.ic_launcher_foreground)
                .setContentIntent(pendingIntent)
                .setOngoing(true);

        if(DEBUG) Log.i(TAG,"Notification Created");
        startForeground(1, builder.build());
    }

}
 
Example 10
Project: QuranAndroid   File: AudioService.java   View Source Code Vote up 6 votes
@Override
public void onCreate() {
    super.onCreate();
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(phoneReceiver,new IntentFilter("receive_incoming_call"));
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(phoneReceiver,new IntentFilter("rejected_incoming_call"));
    LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(phoneReceiver,new IntentFilter("EXTRA_STATE_OFFHOOK"));
    //media player intents
    IntentFilter mediaPlayerFilter = new IntentFilter();
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.PLAY);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.PAUSE);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.BACK);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.FORWARD);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.STOP);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.REPEAT_ON);
    mediaPlayerFilter.addAction(AppConstants.MediaPlayer.REPEAT_OFF);
    mediaPlayerFilter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);
    registerReceiver(MediaPlayerBroadcast, mediaPlayerFilter);

    //screen on / of guard key unlock flag
    IntentFilter screenIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    screenIntentFilter.addAction(Intent.ACTION_SCREEN_ON);
    screenIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
    screenIntentFilter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(MediaPlayerNotificationShow, screenIntentFilter);


}
 
Example 11
Project: FakeLock   File: LockScreenService.java   View Source Code Vote up 6 votes
@Override
public void onCreate() {

    //Start listening for the Screen On, Screen Off, and Boot completed actions
    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    filter.addAction(Intent.ACTION_BOOT_COMPLETED);

    //Set up a receiver to listen for the Intents in this Service
    receiver = new LockScreenReceiver();
    registerReceiver(receiver, filter);
    super.onCreate();
}
 
Example 12
Project: StartBluetooth   File: Service.java   View Source Code Vote up 6 votes
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
            IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
            context.getApplicationContext().registerReceiver(this, filter);
            setBluetooth(context, R.string.pref_set_on_boot);
            break;
        case Intent.ACTION_SCREEN_ON:
            setBluetooth(context, R.string.pref_set_on_screen_on);
            break;
    }
}
 
Example 13
Project: StartBluetooth   File: SettingsActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings_activity);

    if (savedInstanceState == null) {
        Fragment preferenceFragment = new BluetoothFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.pref_container, preferenceFragment);
        ft.commit();
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    registerReceiver(new Service(), filter);
}
 
Example 14
Project: InitialVolume   File: SettingsActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings_activity);

    if (savedInstanceState == null) {
        Fragment preferenceFragment = new VolumeFragment();
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.pref_container, preferenceFragment);
        ft.commit();
    }

    IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
    registerReceiver(new Service(), filter);
}
 
Example 15
Project: Pixel-Activity-Keep-Alive   File: PixelActivityUnion.java   View Source Code Vote up 6 votes
private void doRegister() {

        if (mContext == null)
            throw new NullPointerException("context is null");
        if (activity == null)
            throw new NullPointerException("target activity must nonnull");
        Log.i("Infoss", "已经注册广播");
        mScreenStateBroadcast = new ScreenStateBroadcast();
        IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        mIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
        mContext.registerReceiver(mScreenStateBroadcast, mIntentFilter);
    }
 
Example 16
Project: Linphone4Android   File: LinphoneManager.java   View Source Code Vote up 5 votes
private synchronized void initLiblinphone(LinphoneCore lc) throws LinphoneCoreException {
	mLc = lc;

	PreferencesMigrator prefMigrator = new PreferencesMigrator(mServiceContext);
	prefMigrator.migrateRemoteProvisioningUriIfNeeded();
	prefMigrator.migrateSharingServerUrlIfNeeded();
	prefMigrator.doPresenceMigrationIfNeeded();

	if (prefMigrator.isMigrationNeeded()) {
		prefMigrator.doMigration();
	}

	// Some devices could be using software AEC before
	// This will disable it in favor of hardware AEC if available
	if (prefMigrator.isEchoMigratioNeeded()) {
		Log.d("Echo canceller configuration need to be updated");
		prefMigrator.doEchoMigration();
		mPrefs.echoConfigurationUpdated();
	}

	mLc.setZrtpSecretsCache(basePath + "/zrtp_secrets");

	try {
		String versionName = mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionName;
		if (versionName == null) {
			versionName = String.valueOf(mServiceContext.getPackageManager().getPackageInfo(mServiceContext.getPackageName(), 0).versionCode);
		}
		mLc.setUserAgent("LinphoneAndroid", versionName);
	} catch (NameNotFoundException e) {
		Log.e(e, "cannot get version name");
	}

	mLc.setRingback(mRingbackSoundFile);
	mLc.setRootCA(mLinphoneRootCaFile);
	mLc.setPlayFile(mPauseSoundFile);
	mLc.setChatDatabasePath(mChatDatabaseFile);
	mLc.setCallLogsDatabasePath(mCallLogDatabaseFile);
	mLc.setFriendsDatabasePath(mFriendsDatabaseFile);
	mLc.setUserCertificatesPath(mUserCertificatePath);
	subscribeFriendList(mPrefs.isFriendlistsubscriptionEnabled());
	//mLc.setCallErrorTone(Reason.NotFound, mErrorToneFile);
	enableDeviceRingtone(mPrefs.isDeviceRingtoneEnabled());

	int availableCores = Runtime.getRuntime().availableProcessors();
	Log.w("MediaStreamer : " + availableCores + " cores detected and configured");
	mLc.setCpuCount(availableCores);

	mLc.migrateCallLogs();

	if (mServiceContext.getResources().getBoolean(R.bool.enable_push_id)) {
		initPushNotificationsService();
	}

	/*
	 You cannot receive this through components declared in manifests, only
	 by explicitly registering for it with Context.registerReceiver(). This is a protected intent that can only
	 be sent by the system.
	*/
	mKeepAliveIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
	mKeepAliveIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
	mKeepAliveReceiver = new KeepAliveReceiver();
	mServiceContext.registerReceiver(mKeepAliveReceiver, mKeepAliveIntentFilter);

	updateNetworkReachability();

	resetCameraFromPreferences();

	accountCreator = LinphoneCoreFactory.instance().createAccountCreator(LinphoneManager.getLc(), LinphonePreferences.instance().getXmlrpcUrl());
	accountCreator.setDomain(getString(R.string.default_domain));
	accountCreator.setListener(this);
}
 
Example 17
Project: Crimson   File: SleepBetter.java   View Source Code Vote up 5 votes
private void activateDigitalEyeStrainMonitoring() {

        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);

        getActivity().registerReceiver(mReceiver, filter);

        ScreenReceiver.scheduleAlarmNow(getActivity());

        Toast.makeText(getActivity(), "Monitoring started successfully.", Toast.LENGTH_LONG).show();
        monitoring = true;
        strainButton.setText("Stop Monitoring");


        SharedPreferences.Editor editor = getActivity().getSharedPreferences("monitoring", MODE_PRIVATE).edit();
        editor.putBoolean("digital_monitoring", true);
        editor.apply();

    }