Reading incoming sms crashes on LG P970

51 views Asked by At

Recently i am getting full of crash reports from one phone: LG-P970. What i am doing is reading sms when the sms is received. Nothing unusual. And my codes working on other all phones.

Android – Listen For Incoming SMS Messages

Like in linked answer, i have almost the same code

public class SmsReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        try {
            if (!Build.MODEL.equals("LG-P970")) {
                final Bundle bundle = intent.getExtras();
                if (bundle != null) {
                    final Object[] pdusObj = (Object[]) bundle.get("pdus");
                    String message = "";
                    String senderNum = "";
                    SmsMessage currentMessage;
                    for (int i = 0; i < pdusObj.length; i++) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            String format = bundle.getString("format");
                            currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i], format);
                        } else {
                            currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                        }
                        senderNum = currentMessage.getDisplayOriginatingAddress();
                        message = message + currentMessage.getDisplayMessageBody();

                    }
                    //some logic 
                    ...

                }
            }

        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" + e);

        }

    }
}

But one phone, crashed on this line SmsMessage.createFromPdu((byte[]) pdusObj[i]); The crash happening while the code in 'try-catch' block.

Here my error log

Fatal Exception: java.lang.ExceptionInInitializerError
       at com.a.b.c.SmsReceiver.void onReceive(android.content.Context,android.content.Intent)(SourceFile:38)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2139)
       at android.app.ActivityThread.access$1500(ActivityThread.java:129)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4516)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
       at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10015 nor current process has android.permission.READ_PHONE_STATE.
       at android.os.Parcel.readException(Parcel.java:1327)
       at android.os.Parcel.readException(Parcel.java:1281)
       at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getSubscriberId(IPhoneSubInfo.java:223)
       at android.telephony.TelephonyManager.getSubscriberId(TelephonyManager.java:720)
       at com.android.internal.telephony.lgeAutoProfiling.getInstanceSimInfo(lgeAutoProfiling.java:449)
       at com.android.internal.telephony.lgeAutoProfiling.StartProfiling(lgeAutoProfiling.java:542)
       at com.android.internal.telephony.lgeAutoProfiling.getValue(lgeAutoProfiling.java:495)
       at com.android.internal.telephony.lgeAutoProfiling.getInteger(lgeAutoProfiling.java:325)
       at android.telephony.SmsMessage.(SmsMessage.java:218)
       at com.a.b.c.SmsReceiver.void onReceive(android.content.Context,android.content.Intent)(SourceFile:38)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2139)
       at android.app.ActivityThread.access$1500(ActivityThread.java:129)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.app.ActivityThread.main(ActivityThread.java:4516)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:511)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
       at dalvik.system.NativeStart.main(NativeStart.java)

Yes, i have added in to manifest.

<receiver android:name=".c.SmsReceiver">
   <intent-filter>
     <action android:name="android.provider.Telephony.SMS_RECEIVED" />
   </intent-filter>
</receiver>

Yes i get the permissions.

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

Question

So my question is there is any solution for this? I don't want to add another permission for only one phone.

I am currently ignoring this phone for reading sms state.

    if (!Build.MODEL.equals("LG-P970")) { ... }
0

There are 0 answers