github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/app/GoNativeActivity.java (about) 1 package org.golang.app; 2 3 import android.app.Notification; 4 import android.app.NotificationManager; 5 import android.content.pm.ActivityInfo; 6 import android.app.NativeActivity; 7 import android.content.pm.PackageManager; 8 import android.os.Bundle; 9 import android.util.Log; 10 import android.content.Intent; 11 import android.net.Uri; 12 import android.app.PendingIntent; 13 import android.content.Context; 14 import android.widget.Toast; 15 import android.app.TaskStackBuilder; 16 import android.support.v4.app.NotificationCompat; 17 import android.view.KeyCharacterMap; 18 19 public class GoNativeActivity extends NativeActivity { 20 21 private static GoNativeActivity goNativeActivity; 22 23 public GoNativeActivity() { 24 super(); 25 Log.d("Go", "GoNativeActivity"); 26 goNativeActivity = this; 27 } 28 29 public void openBrowser(String url) { 30 Intent intent = new Intent(Intent.ACTION_VIEW); 31 Uri data = Uri.parse("http://localhost:8089"); 32 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 33 intent.setData(data); 34 startActivity(intent); 35 } 36 37 public void notif(String title, String text) { 38 39 Log.d("Go", "GoNativeActivity notif"); 40 41 Intent intent = new Intent("org.golang.app.MainActivity"); 42 43 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); 44 mBuilder.setSmallIcon(R.drawable.icon); 45 mBuilder.setContentTitle(title); 46 mBuilder.setContentText(text); 47 48 Intent resultIntent = new Intent(this, MainActivity.class); 49 TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 50 stackBuilder.addParentStack(MainActivity.class); 51 52 // Adds the Intent that starts the Activity to the top of the stack 53 stackBuilder.addNextIntent(resultIntent); 54 PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT); 55 mBuilder.setContentIntent(resultPendingIntent); 56 57 NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 58 59 // notificationID allows you to update the notification later on. 60 mNotificationManager.notify(2, mBuilder.build()); 61 62 } 63 64 String getTmpdir() { 65 return getCacheDir().getAbsolutePath(); 66 } 67 68 String getFilesdir() { 69 return getExternalFilesDir(null).getAbsolutePath(); 70 } 71 72 int getRune(int deviceId, int keyCode, int metaState) { 73 try { 74 int rune = KeyCharacterMap.load(deviceId).get(keyCode, metaState); 75 if (rune == 0) { 76 return -1; 77 } 78 return rune; 79 } catch (KeyCharacterMap.UnavailableException e) { 80 return -1; 81 } catch (Exception e) { 82 Log.e("Go", "exception reading KeyCharacterMap", e); 83 return -1; 84 } 85 } 86 87 public static void load() { 88 89 Log.d("Go", "GoNativeActivity load"); 90 // Interestingly, NativeActivity uses a different method 91 // to find native code to execute, avoiding 92 // System.loadLibrary. The result is Java methods 93 // implemented in C with JNIEXPORT (and JNI_OnLoad) are not 94 // available unless an explicit call to System.loadLibrary 95 // is done. So we do it here, borrowing the name of the 96 // library from the same AndroidManifest.xml metadata used 97 // by NativeActivity. 98 try { 99 System.loadLibrary("dcoin"); 100 101 } catch (Exception e) { 102 Log.e("Go", "loadLibrary failed", e); 103 } 104 } 105 106 public void onStart(Bundle savedInstanceState) { 107 Log.d("Go", "GoNativeActivity onStart"); 108 } 109 110 @Override 111 public void onCreate(Bundle savedInstanceState) { 112 Log.d("Go", "GoNativeActivity onCreate"); 113 super.onCreate(savedInstanceState); 114 } 115 }