I am new to Android development, this is the first time that I am providing a list of applications installed in the preferences screen .
Public class AppSelectorPreference ListPreference Expanded {public} I will use the selected value from this list to launch the user's selection app.
App SelectorPreference (context reference, attributect etter) {super (context, ethers); PackageManager pm = context.getPackageManager (); & Lt; PackageInfo & gt; AppListInfo = pm.get installed package (0); Charsoop [] entries = new squarefans [appListInfo.size ()]; Verb [] entry value = new squaresfans [appellant.info (size)]; {Int i = 0; (PackageInfoP: AppLife Infofu) {if (p.applicationInfo.uid> 10000) {entries [i] = p.applicationInfo.loadLabel (pm) .toString (); Entry value [i] = p.applicationInfo.packageName.toString (); Log D. (Bt, "label:" + entries [i]); Log D. (BT, "Ponym:" + Entry Value [ii]); I ++; }}} Hold (exception e) {Log.e (BT, "ER> Put descriptive error message here"); E.printStackTrace (); } SetEntries (entries); SetEntryValues (entryValues); }}
This is added to the following XML in the My Preferences screen:
& preferences> Category: Android: Title = "Launch App" & Gt; Android: Checkbox Launch Android: Title = "Launch App" Android: Summary = "Launch App" Android: defaultValue = "false" android: key = "pref_connect_launch_enable" Android: Dependency = "pref_connect_enable" /> & Lt; Com.nirsoftware.AppSelectorPreference Android: Title = "Select App" Android: Summary = "Select the app to launch Android": key = "pref_connect_package_name" android: dependency = "pref_connect_launch_enable" /> & Lt; / PreferenceCategory & gt; It seems that everything is working properly, until the AppSelector does not click on the preference, which throws an NPE in Android. Preference.ListPreference.findIndexOfValue (ListPreference.java:169) Any suggestions?
I have tried to code your code, and it works fine for me, both of which By adding prefence in a way like this: Appaselectorpreference pref 2 = new appressorpressions (this, blank); . GetPreferenceScreen () addPreference (pref2); And as you use the written XML, which line is 169 where the error is showing?
In addition to this, have you seen to see the log-eca that if any of the app names or labels is empty? I think the only thing is that your Android has different apps for me.
Edit: Sorry, I tested again and now I do not believe you got the same error, what I did, besides choosing the value,
However, By overriding the FindIndexOfValue method I have done this test:
@ Override public int index and exeff value (string value) {return 0; // return super.findIndexOfValue (value); } But of course you have to implement to find the index of that value. Too many entries may be an Android bug for array?
Comments
Post a Comment