In summary my application calls a Raspberry with GPS that cuts the call and answers with an SMS with the coordinates in which it is.
With my code I can call it, but when I receive the SMS I can not get my APP to detect it and read the content.
I have created this BroadcastReceiver
from which I pretend that when the message arrives I save the information in a file, but the app never enters this receiver:
public class MessageReceiver extends BroadcastReceiver{
private int num;
private int UBIC=615202383;
private String numero="0";
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(bundle !=null){
Object[] sms = (Object[]) bundle.get("pdus");
for (int i=0; i<sms.length;i++){
SmsMessage mensajes = SmsMessage.createFromPdu((byte[]) (sms[i]));
String numero = mensajes.getDisplayOriginatingAddress();
String coordenadas = mensajes.getMessageBody().toString();
num = Integer.parseInt(numero);
if(num == UBIC ){
Toast.makeText(context,"Posición recibida de: "+ numero +": "+coordenadas,Toast.LENGTH_SHORT).show();
//Guardar en fichero cuando funcione...
}
}
}
}
}
My Manifest is this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hector.tfgapp">
<!--
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_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/logo5"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<service android:name=".MiIntentService" />
<receiver android:name=".MessageReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
</manifest>
If there is any other easier way to do it, I would appreciate the information.