Problems with Sms Receiver Android Studio

0

I have a strange problem since the SMS Receiver is ignored by phones of the Samsung brand (I tested it with the Note 8 model and another one that I do not remember what it was). What happens is that these phones when they receive a message is as if they ignored, I tested the application in other brands like Sony and the truth went very well. I leave the code to see if someone can guide me. From already thank you very much.

public class SmsReceiver extends BroadcastReceiver {

private static SmsListener mListener;

@Override
public void onReceive(Context context, Intent intent) {
    Bundle data  = intent.getExtras();

    Object[] pdus = (Object[]) data.get("pdus");

    for(int i=0;i<pdus.length;i++){

        SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);


        String numeroEmisor = smsMessage.getOriginatingAddress(); // TRAE EL NUMERO DEL REMITENTE SMS
            String cuerpoDelMensaje = smsMessage.getMessageBody();
            System.out.println("ESTO TRAE EL MESSENGERBOCY DE SMS RECEIVER " + cuerpoDelMensaje);
            mListener.messageReceived(cuerpoDelMensaje,numeroEmisor);



    }
}

public static void bindListener(SmsListener listener) {
    mListener = listener;

}

}

the Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ar.com.micronauta.gpscontrol">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

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

<uses-permission android:name="com.android.providers.telephony.SmsProvider" />


<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
    android:allowBackup="true"
    android:icon="@drawable/motologin_icon"
    android:label="@string/nombre_app"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <!--  <activity
          android:name=".LoginActivity"
          android:label="@string/app_name"
        >-->
    <activity
        android:name=".LoginActivity"
        android:screenOrientation="portrait"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

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

    <activity
        android:name=".RegistrarActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        android:screenOrientation="portrait"/>
    <activity android:name=".MainActivity"

        android:screenOrientation="portrait"/>

</application>

and the mainActivity is in the oncreate part.

        SmsReceiver.bindListener(new SmsListener() {   ///actua cada vez que ingresa un nuevo SMS a la bandeja de entrada
        @Override
        public void messageReceived(String cuerpoDelMensaje,String numeroEmisor) {
            int iniciolatitud, finlatitud, iniciolongitud, finlongitud, finlongitudS = 0;
            String longitud = "";
            String latitud = "";

            if (numeroEmisor.equals(getString(R.string.numeroemisorGPS)) ) {    // consulto que el numero de emisor que quiero se encuentre en la bandeja de entrada y tomo la partes del mensaje que me interesan.
                iniciolatitud = cuerpoDelMensaje.indexOf("lat:") + 4;
                finlatitud = cuerpoDelMensaje.indexOf("long");
                iniciolongitud = cuerpoDelMensaje.indexOf("long") + 5;
                finlongitud = cuerpoDelMensaje.indexOf(",T:");
                finlongitudS = cuerpoDelMensaje.indexOf("speed");
                if (finlongitudS > finlongitud) {
                    latitud = cuerpoDelMensaje.substring(iniciolatitud,finlatitud);
                    longitud = cuerpoDelMensaje.substring(iniciolongitud,finlongitudS);
                } else if ((finlongitudS < finlongitud)) {
                    latitud = cuerpoDelMensaje.substring(iniciolatitud,finlatitud);
                    longitud = cuerpoDelMensaje.substring(iniciolongitud,finlongitud);
                }
                if (iniciolatitud > 4) {
                    final WebView webView = (WebView) findViewById(R.id.webView);
                    webView.getSettings().setJavaScriptEnabled(true);
                    webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
                    webView.setWebViewClient(new WebViewClient());
                    webView.loadUrl("http://maps.google.com/maps?f=q&q=" + latitud.trim() + "," + longitud.trim() + "&z=17");
                    //webView.setWebViewClient(new WebViewClient() {
                    //    @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                    //    webView.loadUrl("file:///android_asset/erroryaviene.html");
                    //          } });
                    Log.e("ya viene","http://maps.google.com/maps?f=q&q=" + latitud.trim() + "," + longitud.trim() + "&z=16");
                    //   Log.e("ya viene",""+latitud);
                    Log.e("PERMISOS","ingresa al mapa");

                }else { //EN CASO DE QUE EL MENSAJE NO SEA EL DE ACTUALIZAR EL MAPA, MOSTRARÁ DICHO SMS EN UNA VENTANA EMERGENTE
                    TextView txtmensaje;
                    Button btnFollow;
                    myDialog.setContentView(R.layout.sms_popup);
                    txtmensaje = (TextView) myDialog.findViewById(R.id.txtmensaje);
                    txtmensaje.setText(cuerpoDelMensaje);
                    btnFollow = (Button) myDialog.findViewById(R.id.btnfollow);
                    btnFollow.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            myDialog.dismiss();
                        }
                    });
                    myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
                    myDialog.show();
                }
                progressBar.setVisibility(View.INVISIBLE);  //OCULTO  EL PROGRESSBAR
                textBuscando.setAlpha(0); //OCULTO LA IMAGEN Y TEXTO DEL PROGRESSBAR
            }
       }
    });
    
asked by Luis 07.12.2018 в 02:47
source

0 answers