JNI的一些知识:

JNI字段描述符“([Ljava/lang/String;)V”

2012-05-31 12:16:09| 分类: Android |举报|字号 订阅

“([Ljava/lang/String;)V” 它是一种对函数返回值和参数的编码。这种编码叫做JNI字段描述符(JavaNative Interface FieldDescriptors)。一个数组int[],就需要表示为这样"[I"。如果多个数组double[][][]就需要表示为这样 "[[[D"。也就是说每一个方括号开始,就表示一个数组维数。多个方框后面,就是数组 的类型。

如果以一个L开头的描述符,就是类描述符,它后紧跟着类的字符串,然后分号“;”结束。

比如"Ljava/lang/String;"就是表示类型String;

"[I"就是表示int[];

"[Ljava/lang/Object;"就是表示Object[]。

JNI方法描述符,主要就是在括号里放置参数,在括号后面放置返回类型,如下:

(参数描述符)返回类型

当一个函数不需要返回参数类型时,就使用”V”来表示。

比如"()Ljava/lang/String;"就是表示String f();

"(ILjava/lang/Class;)J"就是表示long f(int i, Class c);

"([B)V"就是表示void String(byte[] bytes);

Java 类型

符号

Boolean

Z

Byte

B

Char

C

Short

S

Int

I

Long

J

Float

F

Double

D

Void

V

objects对象

以"L"开头,以";"结尾,中间是用"/" 隔开的包及类名。比如:Ljava/lang/String;如果是嵌套类,则用$来表示嵌套。例如 "(Ljava/lang/String;Landroid/os/FileUtils$FileStatus;)Z"

另外数组类型的简写,则用"["加上如表A所示的对应类型的简写形式进行表示就可以了,

比如:[I 表示 int [];[L/java/lang/objects;表示Objects[],另外。引用类型(除基本类型的数组外)的标示最后都有个";"

例如:

"()V" 就表示void Func();

"(II)V" 表示 void Func(int, int);

"(Ljava/lang/String;Ljava/lang/String;)I".表示 int Func(String,String)

对于Qt来说:和android交互就是:
QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);
QAndroidJniObject::callStaticMethod("org/qtproject/example/notification/NotificationClient",
"notify",
"(Ljava/lang/String;)V",
javaNotification.object());

然后写一个java的文件:
/****************************************************************************

Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal

This file is part of the QtAndroidExtras module of the Qt Toolkit.

$QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.

GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.

In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.

$QT_END_LICENSE$

**************************************************************************/

package org.qtproject.example.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;

public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
{
private static NotificationManager m_notificationManager;
private static Notification.Builder m_builder;
private static NotificationClient m_instance;

public NotificationClient()
{
    m_instance = this;
}

public static void notify(String s)
{
    if (m_notificationManager == null) {
        m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
        m_builder = new Notification.Builder(m_instance);
        m_builder.setSmallIcon(R.drawable.icon);
        m_builder.setContentTitle("A message from Qt!");
    }

    m_builder.setContentText(s);
    m_notificationManager.notify(1, m_builder.build());
}

}

就可以让qt往android手机上上推送消息。

转载于:https://www.cnblogs.com/xianqingzh/p/4332532.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值