4

I am try to auto verify SMS on my application is perfectly done all other devices but in RedMi phone it is not works.SMS receiver class not fired when sms is come into the deceive.

here my manisfest:-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

    <permission
        android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-feature android:name="android.hardware.camera"
        android:required="false" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
        android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.Controller"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/MyMaterialTheme"
        android:largeHeap="true">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Login"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".ListOfClass"
            android:screenOrientation="portrait">
        </activity>
        <activity
            android:name=".EditProfile"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".ShowStudentList"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <receiver
            android:enabled="true"
            android:exported="true"
            android:name="student.skoolstar.android.catalyst.com.schoolstar.skoolstarstudent.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter android:priority="999">

                <action android:name="android.intent.action.BOOT_COMPLETED" />

                <action android:name="android.intent.action.QUICKBOOT_POWERON" />

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="schoolstar.com.catalyst.android.skoolstar" />
            </intent-filter>
        </receiver>

        <service android:name=".GCMNotificationIntentService" />

        <activity
            android:name=".Attendance"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>

        <activity
            android:name=".NewMessage"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".GroupMessage"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".Test_Chat"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".FeeReport_Activity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".Notification"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".Dashboard"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".Moment"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".Holiday"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".NotificationNew"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".HomeWork"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <activity
            android:name=".Anssheet"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden">
        </activity>
        <receiver android:name=".SMSReceiver"
            android:permission="android.permission.BROADCAST_SMS">
            <intent-filter
                android:enabled="true"
                android:exported="true">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>

    </application>

</manifest>

here my SMSReceiver.java:-

    public class SMSReceiver extends BroadcastReceiver {
    private static final String TAG = SMSReceiver.class.getSimpleName();

    @Override
    public void onReceive(Context context, Intent intent) {
      //  Toast.makeText(context,"msg",Toast.LENGTH_LONG).show();
        final Bundle bundle = intent.getExtras();
        try {
            if (bundle != null) {
                Object[] pdusObj = (Object[]) bundle.get("pdus");
                for (Object aPdusObj : pdusObj) {
                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) aPdusObj);
                    String senderAddress = currentMessage.getDisplayOriginatingAddress();
                    String message = currentMessage.getDisplayMessageBody();
                    Toast.makeText(context,"msg",Toast.LENGTH_LONG).show();

                    Log.e(TAG, "Received SMS: " + message + ", Sender: " + senderAddress);

                    // if the SMS is not from our gateway, ignore the message
                    if (!senderAddress.toLowerCase().contains(Config.SMS_ORIGIN.toLowerCase())) {
                        return;
                    }

                    // verification code from sms
                    String verificationCode = getVerificationCode(message);

                    Log.e(TAG, "OTP received: " + verificationCode);
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception: " + e.getMessage());
        }
    }

    /**
     * Getting the OTP from sms message body
     * ':' is the separator of OTP from the message
     *
     * @param message
     * @return
     */
    private String getVerificationCode(String message) {
        Log.d("msgaya",message);
        String code = null;
        int index = message.indexOf(Config.OTP_DELIMITER);

        if (index != -1) {
            int start = index + 2;
            int length = 6;
            code = message.substring(start, start + length);
            return code;
        }

        return code;
    }
}

Please Help me I am new in android developing. Thanks in advance.

Shirish Herwade
  • 11,461
  • 20
  • 72
  • 111
Anna jain
  • 63
  • 7

0 Answers0