I have a project in which I have to create an application with the following properties:
- No LAUNCHER : category android: name = "android.intent.category.LAUNCHER"
- He should read SMS messages sent from a specific number, and when this happens, start Activity
- Work with most versions of Android (my goal is now from [Froyo, 2.2] to [Kitkat, 4.4] )
So far my problem is that in Kitkat my BoradcastReceiver does not work when the application is just installed, however, if the application starts once, it runs correctly. In previous versions, it behaves correctly. I read that in the version of [HoneyComb 3.1] there have been changes in the broadcast system, for example this question shows that my problem is known.
My question is: is there a way to install APP and not shut up until it is needed. For example, how do they work on versions below [Honeycomb]?
- If so, can someone indicate the direction.
- If not, would I launch the application once at boot time, and then close it would be a reasonable approach?
- In any case: what do I create βfeelsβ wrong, since what I do is considered bad practice? My system requires the user to actively install the APP, and the APP aims to initiate additional sounds / movement during the message to indicate that the user is at physical risk. The system is used to suggest that the user, his house or part of his / her property is in direct danger, so he should wake up and notify him / her in most cases.
MANIFESTO:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <application android:allowBackup="true" android:icon="@drawable/ic_iconedesktop" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".SMSbroadcastReceptor"> <intent-filter> <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> </application>
RECEIVER
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsManager; import android.telephony.SmsMessage; import android.util.Log; import android.widget.Toast; public class SMSbroadcastReceptor extends BroadcastReceiver { final SmsManager sms = SmsManager.getDefault(); public void onReceive(Context contexto, Intent intencao) { final Bundle bundle = intencao.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); String quem = ""; String mensagem = ""; for (int i = 0; i < pdusObj.length; i++) { SmsMessage smsRecebido = SmsMessage.createFromPdu((byte[]) pdusObj[i]); quem = smsRecebido.getDisplayOriginatingAddress(); mensagem = smsRecebido.getDisplayMessageBody(); Log.i("SMSbroadcastReceptor", "Quem: " + quem + "\n, O que: " + mensagem); Toast toast = Toast.makeText(contexto, "Quem: " + quem + "\n, O que: " + mensagem, Toast.LENGTH_LONG); toast.show(); } if (quem.equals("+MY HIDDEN NUMBER IS HERE")) {
}
source share