java - How to get variables from AndroidJavaObject into a C# class using Unity3D -
i can't find how listarray
variables androidjavaobject
in c#.
i'm trying make for
function using count
number of items in listarray
stored androidjavaobject
. need know how count
androidjavaobject
, how use properly.
i'm using variables, notice "packages" not androidjavaobject[]
.
androidjavaclass jc = new androidjavaclass("com.unity3d.player.unityplayer"); androidjavaobject currentactivity = jc.getstatic<androidjavaobject>("currentactivity"); int flag = new androidjavaclass("android.content.pm.packagemanager").getstatic<int>("get_meta_data"); androidjavaobject pm = currentactivity.call<androidjavaobject>("getpackagemanager"); androidjavaobject packages = pm.call<androidjavaobject>("getinstalledapplications", flag);
it's rudimentary @ point, works how installed apps list unity3d?
the progress far stalls @ getting icon, else works perfect, need way either string
links icon somehow, or texture2d
of icon.
alternative use androidjavaobject
contains drawable
if it's texture2d. have no idea how accomplish of though.
another idea had convert variable, byte[]
can transferred , converted back, have yet find method of works under circumstance.
int count = packages.call<int>("size"); androidjavaobject[] links = new androidjavaobject[count]; string[] names = new string[count]; texture2d[] icons = new texture2d[count]; int ii =0; for(int i=0; ii<count;){ //get object androidjavaobject currentobject = packages.call<androidjavaobject>("get", ii ); try{ //try add variables next entry links[i] = pm.call<androidjavaobject>("getlaunchintentforpackage", currentobject.get<androidjavaobject>("processname")); names[i] = pm.call<string>("getapplicationlabel", currentobject); icons[i] = pm.call<texture2d>("getapplicationicon", currentobject); debug.log ("(" + ii + ") " + +" "+ names[i]); //go next app , entry i++; ii++; } catch { //if fails, go next app , try add same entry. debug.log("skipped "+ ii); ii++; } }
i hate ask 2 questions in row here, , apologize having so, difficult , seemingly awkward circumstance, has little no documentation (that can find).
first of docs on interop between unity3d , android scarce @ best.
the important thing interface unity exposes work java object androidjavaobject
, interface has couple of methods defined. can use ones , those.
this means don't count
object when working java array , you'll still working androidjavaobject
.
int count = packages.call<int>("size"); //getting size of array for( int = 0; < count; i++ ) { //getting object @ location androidjavaobject currentobject = packages.call("get", ); //use currentobject using same methods before: call, callstatic, get, getstatic }
i know verbose, , writing code hard test, need make , apk , deploy device check runs.
probably faster way of doing make own java class on java side , expose 1 method gets called unity side. way @ least benefit of static typing when making jar you'll add in plugins/android
folder.
Comments
Post a Comment