CyanogenMod/Lineage OS has a feature to turn of the screen by double tapping the status bar. It just turns off the screen, not locking the device. As far as I know, this is not possible with normal apps. The apps on the Store turn off the device by locking the device. I browsed the source code of Lineage OS, and if I understood it correctly, it seemed to use PowerManager.goToSleep()
.
I want to create an app to turn the screen off, for my personal use on a device that runs Lineage OS. Since it is Lineage OS, not a stock ROM, I can do more things such as getting the root access or flashing something.
But according to this question, that method is not accessible to third-party apps. I created a simple project and called that method, but when I tried to build the project, "error: cannot find symbol method goToSleep(int)" happened.
Can I create an app that calls that method using Android Studio and the official SDK? If not, how can I build the app that calls that method?
Added the code as requested:
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
pm.goToSleep(100);
}
}
Manifest:
<manifest package="com.example.turnofftest"
xmlns:android="http://schemas.android.com/apk/res/android">
....
<uses-permission android:name="android.permissions.DEVICE_POWER" />
</manifest>
After reading the question "ApriOri" told, I knew I have to sign the app using the platform's certificate, which I can probably do, as Lineage OS is open-source. But first, I need to build it.