github.com/acrespo/mobile@v0.0.0-20190107162257-dc0771356504/bind/java/LoadJNI.java (about) 1 // Copyright 2015 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 package go; 6 7 import android.app.Application; 8 import android.content.Context; 9 10 import java.util.logging.Logger; 11 12 // LoadJNI is a shim class used by 'gomobile bind' to auto-load the 13 // compiled go library and pass the android application context to 14 // Go side. 15 // 16 // TODO(hyangah): should this be in cmd/gomobile directory? 17 public class LoadJNI { 18 private static Logger log = Logger.getLogger("GoLoadJNI"); 19 20 public static final Object ctx; 21 22 static { 23 System.loadLibrary("gojni"); 24 25 Object androidCtx = null; 26 try { 27 // TODO(hyangah): check proguard rule. 28 Application appl = (Application)Class.forName("android.app.AppGlobals").getMethod("getInitialApplication").invoke(null); 29 androidCtx = appl.getApplicationContext(); 30 } catch (Exception e) { 31 log.warning("Global context not found: " + e); 32 } finally { 33 ctx = androidCtx; 34 } 35 } 36 } 37