且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Qt的Andr​​oid手机震动

更新时间:2023-02-26 21:44:02

从我能从的文档 QAndroidJniObject :: fromString 返回一个对象包装Java字符串与你给内容fromString

From what I could gather from the documentation, QAndroidJniObject::fromString returns an object wrapping a Java string with the contents that you gave to fromString.

所以,你在做什么,现在就好像是你做了Java中的以下内容:

So what you're doing right now is as if you had done the following in Java:

Object vibrator = getSystemService("Context.VIBRATOR_SERVICE");

当你真正想要的是:

Object vibrator = getSystemService(Context.VIBRATOR_SERVICE);

因此​​,而不是使用 QAndroidJniObject :: fromString 你也应该可以做这样的事情:

So instead of using QAndroidJniObject::fromString you probably ought to be doing something like this:

QAndroidJniObject serviceName = 
    QAndroidJniObject::getStaticObjectField<jstring>(
        "android/content/Context",
        "VIBRATOR_SERVICE");

这有可能是你需要删除本地引用服务名之后。