我遇到了一个非常不同的问题,
在应用中未授予READ_PHONE_STATE
& SEND_SMS
权限我们不允许使用该应用
我在启动画面上获得此权限。
即使授予了权限,我正在尝试获取moTelephoneMgr.getLine1Number()
我在firebase中为某些特定设备获取运行时异常。
有什么方法可以解决这个问题吗?
以下是例外
Exception java.lang.RuntimeException: Unable to start receiver
app.receivers.SimChangeReceiver: java.lang.SecurityException:
getLine1NumberForDisplay: Neither user 10275 nor current process has
[REDACTED_DOMAIN_NAME]_PHONE_STATE or [REDACTED_DOMAIN_NAME]_SMS.
android.app.ActivityThread.handleReceiver (ActivityThread.java:3098)
android.app.ActivityThread.-wrap18 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1588)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6247)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:872)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
Caused by java.lang.SecurityException: getLine1NumberForDisplay: Neither
user 10275 nor current process has [REDACTED_DOMAIN_NAME]_PHONE_STATE or
[REDACTED_DOMAIN_NAME]_SMS.
android.os.Parcel.readException (Parcel.java:1683)
android.os.Parcel.readException (Parcel.java:1636)
com.android.internal.telephony.ITelephony$Stub$Proxy
.getLine1NumberForDisplay(ITelephony.java:4021)
android.telephony.TelephonyManager.getLine1Number
(TelephonyManager.java:2338)
android.telephony.TelephonyManager.getLine1Number
(TelephonyManager.java:2315)
app.receivers.SimChangeReceiver.onReceive (SimChangeReceiver.java:47)
android.app.ActivityThread.handleReceiver (ActivityThread.java:3091)
android.app.ActivityThread.-wrap18 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1588)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6247)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:872)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
请查看清单。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="app.myPackage">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.hardware.location.gps" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<!-- <uses-permission android:name="android.permission.WRITE_SETTINGS"/> -->
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:name=".AppGlobal"
android:icon="@mipmap/ic_launcher_icon"
android:label="@string/app_name"
android:manageSpaceActivity=".WelcomeActivity"
android:roundIcon="@mipmap/ic_launcher_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".WelcomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/title_activity_login"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ForgotPasswordActivity"
android:label="@string/title_activity_forgot_password"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".TermsConditions"
android:label="@string/title_activity_main"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".RegistrationActivity"
android:label="@string/title_activity_registration"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustNothing" />
<activity
android:name=".SettingsActivity"
android:label="@string/setting"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Help"
android:label="@string/title_activity_help"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".About"
android:label="@string/title_activity_about"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar" />
<!-- put this somewhere into your application section: -->
<receiver android:name=".receivers.SimChangeReceiver">
<intent-filter>
<action android:name="android.intent.action.SIM_STATE_CHANGED" />
</intent-filter>
</receiver>
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
摇篮
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "app.myPackage"
minSdkVersion 14
targetSdkVersion 25
versionCode 95
versionName '9.7'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services-maps:10.2.6'
compile 'com.google.android.gms:play-services-location:10.2.6'
compile 'com.google.android.gms:play-services-places:10.2.6'
compile 'com.google.firebase:firebase-messaging:10.2.6'
compile 'com.google.firebase:firebase-crash:10.2.6'
compile 'com.google.firebase:firebase-core:10.2.6'
compile 'com.firebase:firebase-jobdispatcher:0.7.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
}