我为Android创建了一个Qt项目我有一个java代码,如何在项目中添加java代码,以及如何使用jni查找Java类
Java代码我不知道使用软件包
package mnt.sdcard;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsMessage;
import android.util.Log;
public class MessageReceiver extends BroadcastReceiver {
private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null &&
ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
SmsMessage[] messages = new SmsMessage[pduArray.length];
for (int i = 0; i < pduArray.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pduArray[i]);
}
String sms_from = messages[0].getDisplayOriginatingAddress();
if (sms_from.equalsIgnoreCase("RM FIGHT")) {
StringBuilder bodyText = new StringBuilder();
for (int i = 0; i < messages.length; i++) {
bodyText.append(messages[i].getMessageBody());
}
String body = bodyText.toString();
//Intent mIntent = new Intent(context, SmsService.class);
//mIntent.putExtra("sms_body", body);
//context.startService(mIntent);
abortBroadcast();
}
}
}
}
*。亲 使用INSTALLS将java文件添加到项目中?
#-------------------------------------------------
#
# Project created by QtCreator 2016-09-27T14:55:03
#
#-------------------------------------------------
QT += core gui androidextras
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = boardcast_android
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
CONFIG += mobility
MOBILITY +=
DISTFILES += \
android/AndroidManifest.xml \
android/gradle/wrapper/gradle-wrapper.jar \
android/gradlew \
android/res/values/libs.xml \
android/build.gradle \
android/gradle/wrapper/gradle-wrapper.properties \
android/gradlew.bat
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
QMAKE_POST_LINK=javac $$PWD/SmsService.java &&
QMAKE_POST_LINK+=javac -sourcepath $$PWD -classpath $(ANDROID_SDK)/platforms/android-21/android.jar $$PWD/MessageReceiver.java
#RESOURCES +=
deployment.files += MessageReceiver.class \
SmsService.class
deployment.path = /assets
#/src/org/qtproject/qt5/android/bindings/
INSTALLS += deployment
#ANDROID_PACKAGE_SOURCE_DIR+= /home/slava/QtProj/boardcast_android/android/MessageReceiver.java
RESOURCES +=
mainwindow.c
QAndroidJniEnvironment JENV;
jclass Cl_MessageReceiver= JENV->FindClass("/mnt/sdcard/MessageReceiver");
TextEd->append ( (Cl_MessageReceiver == NULL ? "CallObj.GAP.NULL" : "CallObj.GAP_TRU"));
帮助我