Reputation: 33
When I am using my phone with android Lollipop all of my functions works good, but, when I am using Android Marshmallow or Jelly Bean app crashes.
Following is the build gradle file for app module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.example.k.sms"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
And this is my logcat when I testing my app in emulator with android Marshmallow
12-26 19:10:41.860 18000-18000/com.example.k.sms D/AndroidRuntime: Shutting down VM
12-26 19:10:41.860 18000-18000/com.example.k.sms E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.k.sms, PID: 18000
java.lang.SecurityException: Sending SMS message: uid 10057 does not have android.permission.SEND_SMS.
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:768)
at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:310)
at android.telephony.SmsManager.sendTextMessage(SmsManager.java:293)
at com.example.k.sms.MainActivity$3.onClick(MainActivity.java:149)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Upvotes: 0
Views: 652
Reputation: 1953
provide sms permission in manifest for lollipop and other lower versions and add Marshmallow permission checks for higher than lollipop as explained in Runtime permissions in android
Upvotes: 0
Reputation: 75635
targetSdkVersion 23
and
java.lang.SecurityException: Sending SMS message: uid 10057 does not have android.permission.SEND_SMS.
It seems you just bumped targetSdk
being unaware of consequences. Marshmallow introduces runtime permissions model that kicks off when you target API23 or higher and your app simply must support new runtime permission model as manifest declared permissions are no longer sufficient in such case.
Quick solution is to set targetSdk
to 22
(or lower) as only then runtime permissions won't kick off. Quoting docs:
On all versions of Android, your app needs to declare both the normal and the dangerous permissions it needs in its app manifest, as described in Declaring Permissions. However, the effect of that declaration is different depending on the system version and your app's target SDK level:
- If the device is running Android 5.1 or lower, or your app's target SDK is 22 or lower: If you list a dangerous permission in your manifest, the user has to grant the permission when they install the app; if they do not grant the permission, the system does not install the app at all.
- If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.
If you require anything not available in older APIs and must keep targetSdk
23 or higher, then you must have runtime permission supported though (there are some external libs helping with this).
Upvotes: 3