2

我在以下代码行中遇到了崩溃:

pkgMrg_global = getActivity().getPackageManager();
apps = pkgMrg_global.getInstalledApplications(0);
//GETTING CRASH AT LINE BELOW
Collections.sort(apps,
                        new ApplicationInfo.DisplayNameComparator(
                                pkgMrg_global));

我不明白是如何Collections.sort导致这种情况的Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10157 nor current process has android.permission.READ_PHONE_STATE

堆栈跟踪

java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)

Caused by: java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10157 nor current process has android.permission.READ_PHONE_STATE.
at android.os.Parcel.readException(Parcel.java:1465)
at android.os.Parcel.readException(Parcel.java:1419)
at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getSubscriberId(IPhoneSubInfo.java:231)
at android.telephony.TelephonyManager.getSubscriberId(TelephonyManager.java:1352)
at android.app.ApplicationPackageManager.getSimOperatorNameForStk(ApplicationPackageManager.java:1548)
at android.app.ApplicationPackageManager.getText(ApplicationPackageManager.java:1109)
at android.content.pm.PackageItemInfo.loadLabel(PackageItemInfo.java:115)
at android.app.ApplicationPackageManager.getApplicationLabel(ApplicationPackageManager.java:1186)
at android.content.pm.ApplicationInfo$DisplayNameComparator.compare(ApplicationInfo.java:561)
at android.content.pm.ApplicationInfo$DisplayNameComparator.compare(ApplicationInfo.java:554)
at java.util.TimSort.binarySort(TimSort.java:261)
at java.util.TimSort.sort(TimSort.java:204)
at java.util.TimSort.sort(TimSort.java:169)
at java.util.Arrays.sort(Arrays.java:2010)
at java.util.Collections.sort(Collections.java:1883)
at com.mavdev.focusoutfacebook.fragments.addablock.apps.Fragment_appsselect_addblock$loadAppsListfromSystem.doInBackground(Fragment_appsselect_addblock.java:1830)
at com.mavdev.focusoutfacebook.fragments.addablock.apps.Fragment_appsselect_addblock$loadAppsListfromSystem.doInBackground(Fragment_appsselect_addblock.java:1802)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
... 4 more
4

2 回答 2

1

根据此处 的谷歌文档注释说注意:如果您的 minSdkVersion 和 targetSdkVersion 值都设置为 3 或更低,系统会隐式授予您的应用此权限。如果您不需要此权限,请确保您的 targetSdkVersion 为 4 或更高。

防护等级:危险

如果是这样,您需要添加权限

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

常量值:“android.permission.READ_PHONE_STATE”

于 2015-09-21T02:46:06.577 回答
0

将此权限添加到您的 android 清单

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

于 2015-09-21T02:28:45.500 回答