android - convert List<ApplicationInfo> to String[ ] -
i need convert list string[ ]. how that?
i tried that:
packagemanager packagemanager = getpackagemanager(); list<applicationinfo> liste_aller_anwendungen = packagemanager.getinstalledapplications(packagemanager.get_meta_data); string[] strings = liste_aller_anwendungen.toarray(new string[liste_aller_anwendungen.size()]);
but produces following logcat errors:
java.lang.arraystoreexception: source[0] of type android.content.pm.applicationinfo cannot stored in destination array of type java.lang.string[] @ java.lang.system.arraycopy(native method) @ java.util.arraylist.toarray(arraylist.java:523) @ de.gestureanywhere.hintergrundservice.ongestureperformed(hintergrundservice.java:152) @ android.gesture.gestureoverlayview.fireongestureperformed(gestureoverlayview.java:729) @ android.gesture.gestureoverlayview.access$400(gestureoverlayview.java:55) @ android.gesture.gestureoverlayview$fadeoutrunnable.run(gestureoverlayview.java:744) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5034) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:795) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:611) @ dalvik.system.nativestart.main(native method)
thanks
first of all:
<t> t[] toarray(t[] a) returns array containing of elements in list in proper sequence (from first last element); runtime type of returned array of specified array.
so notice trying store list of applicationinfo
in list of string
, not possible. way so:
string[] strings = new string[liste_aller_anwendungen.size()]; for(int = 0; < liste_aller_anwendungen.size(); i++) { strings[i] = liste_aller_anwendungen[i].tostring(); // or whatever want, needs `string` }
Comments
Post a Comment