helloJni.java ====================================================
public class HelloJni extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
float f = (float) 1.0;
tv.setText( stringFromJNI(f) );
setContentView(tv);
}
public native String stringFromJNI(float f);
static {
System.loadLibrary("hello-jni");
}
}
hello-jni.c ====================================================
#include <stdio.h>
#include <string.h>
#include <android/log.h> //LogCat
#include <jni.h>
#include "ndk_includes.h"
#define LOG_TAG "hello-jni.c" // log tag text
JNIEXPORT jstring JNICALL
Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv * env, jobject
thiz, jfloat f)
{
__android_log_print(ANDROID_LOG_INFO, LOG_TAG,
"HelloJni_stringFromJNI: arg float = %d", (float)f);
char str[100];
sprintf(str,"HelloJni_stringFromJNI: arg float = %d", (float)f);
return (*env)->NewStringUTF(env, str);
}
LogCat ====================================================
INFO/hello-jni.c(275): HelloJni_stringFromJNI: arg float =
-2136996520
Emulator ====================================================
HelloJni_stringFromJNI: arg float = 0
Application.mk
====================================================
APP_PROJECT_PATH := $(call my-dir)/project
APP_MODULES := hello-jni
APP_OPTIM := debug
# to build against Android platform 5,6, or 7 (beware: undocumented
hack, might not be supported in the future):
APP_PLATFORM := android-4
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
On Jan 28, 11:30 am, David Turner <di...@android.com> wrote:
> you cannot use %d to format a floating point value. Use %g instead
>
> > android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>