not get sms even when set the highest priority and

2019-03-27 06:54发布

问题:

My app does not receive SMS when Go SMS is installed. I set the highest priority and have tried installing my app before installing the Go SMS app. However, Go SMS always get SMS before mine. (The first-app-installed concept doesn't work on my phone.)

I am curious what the Go SMS developers do. How can their app always intercept SMS before mine?

My app works fine without the Go SMS. Anyway, here is my manifest. Maybe I've done something wrong.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.ansmsreceiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.test.ansmsreceiver.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="com.test.ansmsreceiver.SMSReceiver" >
        <intent-filter android:priority="2147483647">
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            <action android:name="android.provider.Telephony.NEW_OUTGOING_SMS" />
        </intent-filter>
    </receiver>
</application>

I found other questions related to my issue but still can't find the way to fix it.

Edit: my test project is on Github: https://github.com/entryleveldev/ansmsreceiver.

Edit2: still not sure how android decides which receiver get the intent first. From what I've tested, Go SMS always gets the intent. UID and install order do not matter. But when I tested my app and Handcent SMS, the install order does matter. Maybe Go SMS uses some kind of a hacky way to do this.

Here's the SmsReceiver in Go SMS manifest.

<receiver android:name=".smspopup.SmsReceiver" android:permission="android.permission.BROADCAST_SMS">
        <intent-filter android:priority="2147483647">
            <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
            <category android:name="android.intent.category.DEFAULT"></category>
        </intent-filter>
        <intent-filter android:priority="2147483647">
            <action android:name="android.provider.Telephony.GSM_SMS_RECEIVED"></action>
            <category android:name="android.intent.category.DEFAULT"></category>
        </intent-filter>
        <intent-filter >
            <action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED"></action>
            <data android:mimeType="application/vnd.wap.mms-message"></data>
        </intent-filter>
        <intent-filter >
            <action android:name="com.android.mms.transaction.MESSAGE_SENT"></action>
        </intent-filter>
    </receiver>

Their default setting is to disable other message notification (abortBroadcast). This is really bad to me.

回答1:

I have faced the same problem.

As per the documentation by Android, Highest priority must be 1000 http://developer.android.com/reference/android/content/IntentFilter.html#SYSTEM_HIGH_PRIORITY

But this application is using a higher priority evading the guidelines.

http://forum.avast.com/offline/forum.theftaware.com/viewtopic5dcd.html

Don't Be Evil You better follow the guidelines.

Cheers



回答2:

As the question you are linking to explains, once the GO SMS app's receiver gets called, they can call abortBroadcast(). Assuming they are using the highest priority possible (=2147483647), I would assume that the following snippet from the docs would apply:

The order receivers run in can be controlled with the android:priority attribute of the matching intent-filter; receivers with the same priority will be run in an arbitrary order.

However, since they always happen to intercept SMS before your app, I would assume that the magic is somewhere else. Among their permissions, they have the following:

  • "android.permission.PERSISTENT_ACTIVITY"
  • "android.permission.WRITE_SMS"
  • "android.permission.READ_SMS"

Do you mind trying a combination of these, to see if it affects the ordering of intent resolution?