github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/example/libhellojni/hello.c (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build android
     6  
     7  // See main.go for commentary.
     8  
     9  #include <android/log.h>
    10  #include <jni.h>
    11  #include <limits.h>
    12  #include "_cgo_export.h"
    13  
    14  JNIEXPORT void JNICALL
    15  Java_demo_Demo_hello(JNIEnv* env, jclass clazz, jstring jname) {
    16  	// Turn Java's UTF16 string into (almost) UTF8.
    17  	const char *name = (*env)->GetStringUTFChars(env, jname, 0);
    18  
    19  	GoString go_name;
    20  	go_name.p = (char*)name;
    21  	go_name.n = (*env)->GetStringUTFLength(env, jname);
    22  
    23  	// Call into Go.
    24  	LogHello(go_name);
    25  
    26  	(*env)->ReleaseStringUTFChars(env, jname, name);
    27  }