github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/example/libhellojni/hello.go (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  package main
     8  
     9  // #cgo LDFLAGS: -llog
    10  // #include <android/log.h>
    11  // #include <string.h>
    12  import "C"
    13  import (
    14  	"fmt"
    15  	"unsafe"
    16  )
    17  
    18  //export LogHello
    19  func LogHello(name string) {
    20  	fmt.Printf("Hello, %s!\n", name)
    21  
    22  	ctag := C.CString("Go")
    23  	cstr := C.CString(fmt.Sprintf("Printing hello message for %q", name))
    24  	C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr)
    25  	C.free(unsafe.Pointer(ctag))
    26  	C.free(unsafe.Pointer(cstr))
    27  }