Documentation for the Unity C# Library
Loading...
Searching...
No Matches
PixoAndroidUtils.cs
Go to the documentation of this file.
1using System;
2
3using UnityEngine;
4
5namespace PixoVR.Apex
6{
7 public static partial class PixoAndroidUtils
8 {
9 #region JAVA OBJECTS
13 public static AndroidJavaObject CurrentActivity
14 {
15 get
16 {
17 if (currentActivity == null)
18 {
19 AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
20 currentActivity = unityPlayer.SafeGetStatic<AndroidJavaObject>("currentActivity");
21 }
22 return currentActivity;
23 }
24 }
25 static AndroidJavaObject currentActivity;
26
27 public static AndroidJavaObject PackageManager
28 {
29 get
30 {
31 if (packageManager == null)
32 packageManager = CurrentActivity.SafeCall<AndroidJavaObject>("getPackageManager");
33 return packageManager;
34 }
35 }
36 static AndroidJavaObject packageManager;
37
41 public static AndroidJavaObject ApplicationContext
42 {
43 get
44 {
45 if (applicationContext == null)
46 applicationContext = CurrentActivity.SafeCall<AndroidJavaObject>("getApplicationContext");
47 return applicationContext;
48 }
49 }
50 static AndroidJavaObject applicationContext;
51
55 public static AndroidJavaObject ApplicationInfo
56 {
57 get
58 {
59 if (applicationInfo == null)
60 applicationInfo = ApplicationContext.SafeCall<AndroidJavaObject>("getApplicationInfo");
61 return applicationInfo;
62 }
63 }
64 static AndroidJavaObject applicationInfo;
65
69 public static AndroidJavaObject NativeUtils
70 {
71 get
72 {
73 if (nativeUtils == null)
74 nativeUtils = new AndroidJavaObject("com.pixovr.pixosdk.PixoUtils", ApplicationContext);
75 return nativeUtils;
76 }
77 }
78 static AndroidJavaObject nativeUtils;
79 #endregion
80
86 public static bool HasIntentExtra(string key)
87 {
88 var intent = CurrentActivity.SafeCall<AndroidJavaObject>("getIntent");
89 var bundle = intent.SafeCall<AndroidJavaObject>("getExtras");
90 if (bundle == null) return false;
91 return bundle.SafeCall<bool>("containsKey", key);
92 }
93
100 public static bool GetIntentBooleanExtra(string key, bool defaultValue)
101 {
102 var intent = CurrentActivity.SafeCall<AndroidJavaObject>("getIntent");
103 return intent.SafeCall<bool>("getBooleanExtra", key, defaultValue);
104 }
105
111 public static string GetIntentStringExtra(string key)
112 {
113 var intent = CurrentActivity.SafeCall<AndroidJavaObject>("getIntent");
114 return intent.SafeCall<string>("getStringExtra", key);
115 }
116
117 public static bool IsAppInstalled(string packageName)
118 {
119 if (NativeUtils != null)
120 return NativeUtils.SafeCall<bool>("isAppInstalled", packageName);
121 return false;
122 }
123
124 public static bool LaunchApp(string packageName, string[] extraKeys, string[] extraValues)
125 {
126 return NativeUtils.SafeCall<bool>("launchApp", packageName, extraKeys, extraValues);
127 }
128 }
129}
static AndroidJavaObject applicationContext
static AndroidJavaObject PackageManager
static AndroidJavaObject CurrentActivity
JNI to call com.unity.player.UnityPlayer.currentActivity()
static string GetIntentStringExtra(string key)
Returns a string from the Android intent extras.
static AndroidJavaObject ApplicationContext
JNI to call CurrentActivity.getApplicationContext()
static AndroidJavaObject packageManager
static AndroidJavaObject ApplicationInfo
JNI to call ApplicationContext.getApplicationInfo()
static AndroidJavaObject NativeUtils
Returns an instance of the PixoUtils.java class in the Apex SDK.
static AndroidJavaObject currentActivity
static bool LaunchApp(string packageName, string[] extraKeys, string[] extraValues)
static bool GetIntentBooleanExtra(string key, bool defaultValue)
Returns a boolean from the Android intent extras.
static AndroidJavaObject nativeUtils
static bool HasIntentExtra(string key)
Returns if the Android intent extras bundle has a key with the given name.
static AndroidJavaObject applicationInfo
static bool IsAppInstalled(string packageName)