2
0
mirror of synced 2025-02-23 23:08:14 +00:00
Hana (Hyang-Ah) Kim 969a1bf7dd example/libhellojni: fix build and allow go get golang.org/x/mobile/...
Change-Id: Id0cd58705c882ea58cedbee5a6e9aff010c0ad4d
Reviewed-on: https://go-review.googlesource.com/1281
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-10 01:38:44 +00:00

28 lines
689 B
C

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build android
// See main.go for commentary.
#include <android/log.h>
#include <jni.h>
#include <limits.h>
#include "_cgo_export.h"
JNIEXPORT void JNICALL
Java_demo_Demo_hello(JNIEnv* env, jclass clazz, jstring jname) {
// Turn Java's UTF16 string into (almost) UTF8.
const char *name = (*env)->GetStringUTFChars(env, jname, 0);
GoString go_name;
go_name.p = (char*)name;
go_name.n = (*env)->GetStringUTFLength(env, jname);
// Call into Go.
LogHello(go_name);
(*env)->ReleaseStringUTFChars(env, jname, name);
}