Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt on Android : How to shutdown the device or simulate the press of Power button
Forum Updated to NodeBB v4.3 + New Features

Qt on Android : How to shutdown the device or simulate the press of Power button

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 1 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nologinma
    wrote on last edited by
    #1

    I'd like to build a small application that reboot the device or better put in PowerOff my device.

    I saw that there are in qt the specific class and the I have call a JNI java class.

    I have assign the right permissiom to my app following:

    @<uses-permission android:name="android.permission.REBOOT"/>
    <uses-permission android:name="android.permission.DEVICE_POWER"/>
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/>@

    and the call in qt c++ to my JNI class is the following:

    @QAndroidJniObject::callStaticMethod<void>("org/qtproject/example/PowerOff/Next72Utility", "powerOff", "()V");@

    and external java class is the following:

    @//
    // Next72Utility.java
    //
    package org.qtproject.example.PowerOff;

    import android.content.Context;

    import android.app.Activity;
    import android.view.WindowManager;
    import android.view.WindowManager.LayoutParams;
    import android.os.PowerManager;

    public class Next72Utility extends org.qtproject.qt5.android.bindings.QtActivity
    {

    public static Next72Utility m_istance;

    public Next72Utility()
    {
    m_istance = this;
    }

    public static void powerOff()
    {
    if (m_istance != null)
    {
    System.out.println("I'm here");
    PowerManager pm = (PowerManager) m_istance.getSystemService(Context.POWER_SERVICE);
    System.out.println("pm = " + pm);
    pm.reboot(null);

       }
    

    }

    @}

    The program is compiled without error and the output (console) is the following (no errors):

    @Starting remote process.D/dalvikvm(24655): Late-enabling CheckJNI
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/lib/libgnustl_shared.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/lib/libgnustl_shared.so 0x4186f148
    D/dalvikvm(24655): No JNI_OnLoad found in /data/data/org.qtproject.example.PowerOff/lib/libgnustl_shared.so 0x4186f148, skipping init
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/lib/libQt5Core.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/lib/libQt5Core.so 0x4186f148
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/lib/libQt5Gui.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/lib/libQt5Gui.so 0x4186f148
    D/dalvikvm(24655): No JNI_OnLoad found in /data/data/org.qtproject.example.PowerOff/lib/libQt5Gui.so 0x4186f148, skipping init
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/lib/libQt5Widgets.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/lib/libQt5Widgets.so 0x4186f148
    D/dalvikvm(24655): No JNI_OnLoad found in /data/data/org.qtproject.example.PowerOff/lib/libQt5Widgets.so 0x4186f148, skipping init
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/lib/libQt5AndroidExtras.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/lib/libQt5AndroidExtras.so 0x4186f148
    D/dalvikvm(24655): No JNI_OnLoad found in /data/data/org.qtproject.example.PowerOff/lib/libQt5AndroidExtras.so 0x4186f148, skipping init
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/qt-reserved-files/plugins/platforms/android/libqtforandroid.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/qt-reserved-files/plugins/platforms/android/libqtforandroid.so 0x4186f148
    I/Qt (24655): qt start
    D/dalvikvm(24655): Trying to load lib /data/data/org.qtproject.example.PowerOff/lib/libPowerOff.so 0x4186f148
    D/dalvikvm(24655): Added shared lib /data/data/org.qtproject.example.PowerOff/lib/libPowerOff.so 0x4186f148
    D/dalvikvm(24655): No JNI_OnLoad found in /data/data/org.qtproject.example.PowerOff/lib/libPowerOff.so 0x4186f148, skipping init
    D/dalvikvm(24655): GC_CONCURRENT freed 341K, 12% free 7160K/8135K, paused 2ms+2ms, total 27ms
    D/dalvikvm(24655): WAIT_FOR_CONCURRENT_GC blocked 10ms
    D/dalvikvm(24655): WAIT_FOR_CONCURRENT_GC blocked 10ms
    D/libEGL (24655): loaded /system/lib/egl/libEGL_mali.so
    D/libEGL (24655): loaded /system/lib/egl/libGLESv1_CM_mali.so
    D/libEGL (24655): loaded /system/lib/egl/libGLESv2_mali.so
    D/ (24655): Device driver API match
    D/ (24655): Device driver API version: 10
    D/ (24655): User space API version: 10
    D/ (24655): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
    D/OpenGLRenderer(24655): Enabling debug mode 0
    I/System.out(24655): I'm here
    I/System.out(24655): pm = android.os.PowerManager@418c2040
    "org.qtproject.example.PowerOff" terminated.@

    but the device is until running......
    Do you have a solution for this problem ?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nologinma
      wrote on last edited by
      #2

      I have read several article and I understand that

      1. to shutdown the device you have to ROOT permission

      2. you can put in sleep mode without ROOT permission but not in shutdown.

      Observation

      I have a SAMSUNG NOTE 10.1 (tablet) and when I press the power button for 1 second the device go to sleep.

      If I press the power button for 3 seconds I have a dialog screen that it propose if I turn off the device or not.

      Then I want to simulate the second case (button for 3 second the power button).

      @void keyPressPowerButton()
      {
      QKeyEvent event(QEvent::KeyPress, Qt::Key_PowerOff, Qt::NoModifier);
      QApplication::sendEvent(mainWindow, &event);
      }@

      But It go in sleep mode not it in shutdown mode (with dialog screen that it propose if I turn off the device or not)

      How can I simulate the Qt::Key_PowerOff for 3 seconds ?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved