• 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手机上上推送消息。

  • 相关阅读:
    C#中Cookies操作
    获取WPF url 地址中的Cookies
    c#的dllimport使用方法详解
    SQLite的原子提交及WAL日志模式 和 SQLite多线程解决方案
    单例模式
    C# 操作 ofd 文件
    .NET Core 3 、WPF MVVM框架 、Prism系列 之经典 博客园友
    .NET Core 3 WPF MVVM框架 Prism系列之事件聚合器
    程序员不得不了解的硬核知识大全
    Invalid prop: custom validator check failed for prop "pagination".
  • 原文地址:https://www.cnblogs.com/xianqingzh/p/4332532.html
Copyright © 2020-2023  润新知