1

I am getting toast even after screen is off(I am using Moto e).when screen is off I am moving my hand over sensor area two or more time and immediately I turn on the screen using power button and unlock the phone and I can see the toast.I can see "see" and "yo" as I coded for near and far and I used Toast.LENGTH_LONG so toast is there for some seconds.

now I want to turn on the screen and and open the screen lock using proximity sensor.

I am still confuse does I am having Android Issue 3708?? Thanks lot.

public void onSensorChanged(SensorEvent event) {
        Log.i(TAG, "onSensorChanged().");
        if(event.values[0]==3.0)
        {
        Toast.makeText(getApplicationContext(), "see", Toast.LENGTH_LONG).show();
       // startService(new Intent(this, TheService.class));
       // i want to open screen lock here
           new ServiceLockTest().data();
        }
        else
            Toast.makeText(getApplicationContext(), "yo", Toast.LENGTH_LONG).show();
        }

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

        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

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

        mWakeLock = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);

        registerReceiver(mReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
    }


     @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, flags, startId);
        Notification.Builder mBuilder =
                new Notification.Builder(getApplicationContext())
        .setContentTitle("see")
        .setSmallIcon(R.drawable.ic_lock_idle_alarm)
        .setContentText("yo");
        notification = mBuilder.build();

        startForeground(Process.myPid(),notification);
        registerListener();
        mWakeLock.acquire();

        return START_STICKY;
    }



 //-------------------------------------------------------------------------------
        public class ServiceLockTest extends Activity {
            public static final String TAG = ServiceLockTest.class.getName();

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

            }

            @Override
            public void onResume() {
                super.onResume();

                startService(new Intent(this, TheService.class));
            }

            void data() {
                // TODO Auto-generated method stub
                Window window = this.getWindow();
                  window.addFlags(LayoutParams.FLAG_DISMISS_KEYGUARD);
                  window.addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED);
                  window.addFlags(LayoutParams.FLAG_TURN_SCREEN_ON);
            }

        }
sunil sarode
  • 154
  • 1
  • 13

0 Answers0