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. Android GetSystemService for Power Manager via Qt

Android GetSystemService for Power Manager via Qt

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 2.5k Views
  • 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.
  • G Offline
    G Offline
    GoodMorninSunshine
    wrote on last edited by
    #1

    Hi All,

    I need some help in using the power services manager in Android. THe code that I need to write in Java is :
    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

    To do this in Qt I have done :
    @QAndroidJniObject activity = QtAndroid::androidActivity()
    QAndroidJniObject context = activity.callObjectMethod("getApplicationContext","()Landroid/content/Context;");
    if(!context.isValid())
    qDebug() << "Context Not Valid";
    QAndroidJniObject powerString = QAndroidJniObject::fromString("power");
    powerManager = context.callObjectMethod("getSystemService", "(Ljava/lang/String;)Landroid/os/PowerManager;", powerString.object<jstring>());
    if(!powerManager.isValid())
    qDebug() << "Power manager invalid";
    else
    powerManager.callObjectMethod( "isScreenOn","()Z");
    @

    I keep getting that power manager is invalid.
    What am I doing wrong?

    I have also tried with @QAndroidJniObject powerString = QAndroidJniObject::fromString("POWER_SERVICE");@ ,
    but still the powerManager is invalid! :(

    Can someone please give me a clue as to how to fix this, or a work around...

    Thanks so much!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Adam
      wrote on last edited by Adam
      #2

      getSystemService(String) returns an Java Object so try

      powerManager = context.callObjectMethod("getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;", powerString.object<jstring>());

      1 Reply Last reply
      1

      • Login

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