我试图从android-ndk中发送短信。当我尝试在sendTextMessage
中调用SmsManager
方法时,我的应用程序崩溃,错误代码为6(中止)。此外,我得到一个错误消息说"在decodeIndirectRef"中无效的间接引用0xe7f03658。我认为它与我的对象引用有关,但是我所使用的对象所使用的对象并没有使用所述的地址。
执行最后一行时应用程序崩溃。我检查了所有异常情况,但没有一个正在上升。
#ifndef NULL
#define NULL ((void *) 0)
#endif
#include <string.h>
#include <jni.h>
#include <android/log.h>
JNIEXPORT void JNICALL Java_tss_challenges_hybrid_App_sendSMS(JNIEnv* env,
jobject thiz) {
jclass smsManagerClz = (*env)->FindClass(env,
"android/telephony/SmsManager");
jmethodID getDefaultMethodID = (*env)->GetStaticMethodID(env, smsManagerClz,
"getDefault", "()Landroid/telephony/SmsManager;");
jobject smsManagerObj = (*env)->CallStaticObjectMethod(env, smsManagerClz,
getDefaultMethodID);
jmethodID sendSMSMethodID = (*env)->GetMethodID(env, smsManagerClz,
"sendTextMessage",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;"
"Landroid/app/PendingIntent;Landroid/app/PendingIntent;)V");
jstring number = (*env)->NewStringUTF(env, "1234");
jstring text = (*env)->NewStringUTF(env, "sms content");
jstring nullString = (*env)->NewStringUTF(env, NULL);
__android_log_print(ANDROID_LOG_VERBOSE, "MyApp", "%x,%x,%x,%x,%x,%x,%x,%x", number, text, nullString,smsManagerObj,sendSMSMethodID,env,smsManagerClz,getDefaultMethodID);
(*env)->CallVoidMethod(env, smsManagerObj, sendSMSMethodID, number, nullString, text, NULL, NULL);
}
日志:
05-11 14:17:00.718: D/dalvikvm(2376): Trying to load lib /data/app-lib/tss.chalenges.hybrid-1/libnativeSMSManager.so 0xb2d5b2d0
05-11 14:17:00.718: D/dalvikvm(2376): Added shared lib /data/app-lib/tss.chalenges.hybrid-1/libnativeSMSManager.so 0xb2d5b2d0
05-11 14:17:00.718: D/dalvikvm(2376): No JNI_OnLoad found in /data/app-lib/tss.chalenges.hybrid-1/libnativeSMSManager.so 0xb2d5b2d0, skipping init
05-11 14:17:00.848: V/MyApp(2376): c2900025,a0f00029,0,ba100021,b0be31c0,b82cff30,b680001d,b0be2f18
05-11 14:17:00.948: W/dalvikvm(2376): Invalid indirect reference 0xe7f03658 in decodeIndirectRef
05-11 14:17:00.948: I/dalvikvm(2376): "main" prio=5 tid=1 RUNNABLE
05-11 14:17:00.948: I/dalvikvm(2376): | group="main" sCount=0 dsCount=0 obj=0xb2a94ca8 self=0xb82d3398
05-11 14:17:00.958: I/dalvikvm(2376): | sysTid=2376 nice=0 sched=0/0 cgrp=apps handle=-1225264812
05-11 14:17:00.958: I/dalvikvm(2376): | state=R schedstat=( 100000000 380000000 94 ) utm=6 stm=4 core=0
05-11 14:17:00.958: I/dalvikvm(2376): at tss.challenges.hybrid.App.sendSMS(Native Method)
05-11 14:17:00.958: I/dalvikvm(2376): at tss.challenges.hybrid.App.onCreate(App.java:36)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.Activity.performCreate(Activity.java:5231)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-11 14:17:00.958: I/dalvikvm(2376): at android.os.Handler.dispatchMessage(Handler.java:102)
05-11 14:17:00.958: I/dalvikvm(2376): at android.os.Looper.loop(Looper.java:136)
05-11 14:17:00.958: I/dalvikvm(2376): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-11 14:17:00.958: I/dalvikvm(2376): at java.lang.reflect.Method.invokeNative(Native Method)
05-11 14:17:00.958: I/dalvikvm(2376): at java.lang.reflect.Method.invoke(Method.java:515)
05-11 14:17:00.958: I/dalvikvm(2376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-11 14:17:00.958: I/dalvikvm(2376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-11 14:17:00.958: I/dalvikvm(2376): at dalvik.system.NativeStart.main(Native Method)
05-11 14:17:00.998: E/dalvikvm(2376): VM aborting
05-11 14:17:01.018: A/libc(2376): Fatal signal 6 (SIGABRT) at 0x00000948 (code=-6), thread 2376 (halenges.hybrid)
答案 0 :(得分:0)
您无需传递NULL STRING,您可以直接在该参数位置传递NULL
。
避免这个
jstring nullString = (*env)->NewStringUTF(env, NULL);
尝试使用NULL
或
jstring nullString = (*env)->NewStringUTF(env, "");