Before Android 4.4 I was able to stop messages from moving to inbox by setting the priority like this
<receiver android:name="com.serviceschedular.helperClasses.SmsReceiver" >
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
and then abortBroadcast() in onRecieve() messages. However in Android 4.4 we need to define SMS_DELIVER_ACTION in order to make our messaging app as default :
Getting Your SMS Apps Ready for KitKat
By doing this I can receive messages first and they don't move to any other messaging app but I also need to send them to messaging app if it doesn't fill my criteria. So is there any way around to achieve this functionality?
Related
I have a simple Android app that does not do anything special except receiving and showing GCM notifications and - then - opening the browser (when a notification is clicked on).
GCM is configured newely as described in the current documentation. The browser is based on the class WebViewClient.
I have noticed that this app consumes 4 or 5 times more battery as any other app installed on my phone. As far as I can understand the BroadcastReceiver is always running which can cause such an extremely high battery usage.
Is there any may to reduce it? Sometimes my smartphone gets really hot without any activity from my side.
The fragment of my Manifest about GCM:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:persistent="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="my.package" />
<category android:name="my.package" />
</intent-filter>
</receiver>
Thank you in advance.
Probably the best that you can do is to implement GCM (Google Cloud Messaging) using pushing instead of polling.
In this way you will be able to get a "tickle" when something new happened and you will know when ask to the server for datas.
I have an app that allows users to forward SMS messages as they are received. Back in the day, I had the android:priority in my intent-filter for android.provider.Telephony.SMS_RECEIVED set to barely above Android's default messaging app. I did so, so that the user can forward the messages without having to clear them in the messaging app. However, a few months later, Go SMS Pro released an update of their app with a android:priority value extremely high, so users with that app installed started having issues. I updated my app so that my priority was slightly higher than Go SMS Pro's and everything went fine. Now Go SMS Pro did it again, their android:priority has been taken up to the max value you can assign. 2147483647 on one of their broadcast receivers and 2147483640 on another (yes, Go SMS Pro has two broadcast receivers now).
To fix this, I tried changing my priority to max just like theirs, but somehow their app keeps wining the SMS fight even though our priorities are the same. I read somewhere that Android when having to decide between two apps with the same priority, it chooses the one installed the earliest. I tried installing Go SMS Pro AFTER my app, but still nothing.
What's the proper way to fix this? What are they doing in their app that makes them get the SMS broadcast before anyone else, even with same android:priority values?
What's the proper way to fix this?
Modify your app to survive being run after Go SMS Pro or any other app. You might also advise users if you detect apps monitoring the same broadcast with equal-or-higher priorities (use PackageManager for this), so they know to configure those apps accordingly.
Trying to have a higher priority than everyone else is an arms race, one in which you will eventually wind up, at best, tied with the same priority. The behavior of ordered broadcasts with tied priorities is undocumented, and therefore there is no guaranteed behavior. Android -- or customized versions of Android -- are welcome to modify the tie-breaker algorithm. That algorithm could be anything from:
alphabetical order by package name
order as found in a hashed collection, where the hash key could be based on anything (e.g., object ID)
random number generator
Since you cannot reliably "win", modify your app to be as successful as possible when you do indeed "lose".
go sms pro has set these lines in it's manifest for SmsReceiver:
<receiver android:name=".smspopup.SmsReceiver" android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.GSM_SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
<intent-filter>
<action android:name="com.android.mms.transaction.MESSAGE_SENT" />
</intent-filter>
</receiver>
all these intent-filters make its priority higher than your receiver even if your reciever has the priority set to 2147483647. you can see the list of all receivers of all apps by:
List<ResolveInfo> receivers = getPackageManager().queryBroadcastReceivers(new Intent("android.provider.Telephony.SMS_RECEIVED"), 0);
the first receiver in the list, receives the sms before than others
Is there a way to programatically disable the user from receiving/sending sms messages?
No, you cannot do this. Maybe on rooted devices etc you could, but it's not standard situation to consider.
I don't know about sending part, but to block receiving sms you can give your app high priority
<receiver android:name=".receiver.SMSReceiver" android:enabled="true">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
and in your BroadcastReceiver's onReceive() method, you can use abortBroadcast(). So that received sms doesn't reach inbox.
I'm writing application which handles SMS's and as I plan it should replace stock/default application.
I'm intercepting android.provider.Telephony.SMS_RECEIVED broadcast fired by incoming SMS and publishing my own notification and then calling abortBroadcast(), so in the end there is no notification for incoming new messages which leads to default/stock app.
But the problem is in fact that when user doesn't read for a long enough time (smth like several minutes) incoming SMS stock/default app aroses another broadcast - I suspect just checking that there's unread sms. So user sees 2 notifications: one from default/stock messaging app and another one from mines, which is messing.
I can't find which broadcast fired when there's unread sms?
Any ideas, hints?
You can set the priority of your receiver this way, so you know that it has the top priority and will execute the onReceive() method:
<receiver android:name=".SmsReceiver" android:enabled="true"
android:exported="true" android:priority="999">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
If i'm developing an alternative Android SMS application, is there any way to replace the default sms application with my, so that my app receives the incoming sms message?
you just have to set a higher priority for your broadcast receiver like this. For example 100
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
Then you have to call abortBroadcast(); when you want it to stop if you dont want it to propagate. This only works for orderedbroadcasts.
You cannot enforce your app on the users. As Corey mentioned users will have to switch off sms notifications in the default app to not getting the notification twice.