Go SMS Pro overriding android.provider.Telephony.S

2019-06-21 19:25发布

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?

2条回答
可以哭但决不认输i
2楼-- · 2019-06-21 19:52

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".

查看更多
看我几分像从前
3楼-- · 2019-06-21 19:57

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

查看更多
登录 后发表回答