我正在开发一个短信/彩信系统,我需要该应用程序才能接收短信和彩信。它接收短信很好。我正在测试一部真正的手机(运行7.01的Galaxy S7 Edge)。
该应用不会收到彩信。根据{{3}},我的清单是正确的:
<receiver android:name="com.webnation.text2email.receivers.MMSBroadcastReceiver"
android:enabled="true"
android:permission="android.permission.BROADCAST_WAP_PUSH"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
但是,在广播接收器的第一行设置断点,从不调用广播接收器。我包括所有正确的权限。
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_MMS"/>
<uses-permission android:name="android.permission.RECEIVE_WAP_PUSH"/>
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="com.android.vending.BILLING" />
我的广播接收器:
public class MMSBroadcastReceiver extends BroadcastReceiver {
private static final String ACTION_MMS_RECEIVED = "android.provider.Telephony.WAP_PUSH_DELIVER";
private static final String MMS_DATA_TYPE = "application/vnd.wap.mms-message";
// Retrieve MMS
public void onReceive(Context context, Intent intent) {
this.context = context; <------- break point set here.
String action = intent.getAction();
String type = intent.getType();
int typeMessage = -1;
byte[] pushData;
GenericPdu pdu = null;
Toast.makeText(context, "MMS received", Toast.LENGTH_LONG).show();
if (action.equals(ACTION_MMS_RECEIVED) && type.equals(MMS_DATA_TYPE)) {
Bundle bundle = intent.getExtras();
Timber.d("bundle " + bundle);
if (bundle != null) {
pushData = intent.getByteArrayExtra("data");
PduParser parser = new PduParser(pushData);
pdu = parser.parse();
PduHeaders headers = pdu.getPduHeaders();
Timber.d("buffer " + pushData);
String incomingNumber = new String(pushData);
int indx = incomingNumber.indexOf("/TYPE"); // not used, parse the number in MMUtils.getAddress instead
if (indx > 0 && (indx - 15) > 0) {
int newIndx = indx - 15;
incomingNumber = incomingNumber.substring(newIndx, indx);
char[] characters = incomingNumber.toCharArray();
int index = 0;
for (int i=0;i<characters.length;i++) {
if (Character.isDigit(characters[i]) ){
index = i;
break;
}
}
//indx = incomingNumber.indexOf("+");
if (index > 0) {
incomingNumber = incomingNumber.substring(index);
TelephonyManager tm = (TelephonyManager)context.getSystemService(context.getApplicationContext().TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso().toUpperCase();
try {
String prefix = CountryToPhonePrefix.prefixFor(countryCode).replace("+", "");
int indexOfBaseNumber = incomingNumber.indexOf(prefix);
if (indexOfBaseNumber > -1) {
if (indexOfBaseNumber == 0) {
int lengthPrefix = prefix.length();
indexOfBaseNumber = indexOfBaseNumber + lengthPrefix;
}
incomingNumber = incomingNumber.substring(indexOfBaseNumber);
}
} catch (IllegalArgumentException ie) {
Timber.e(ie);
} catch (IndexOutOfBoundsException ie) {
Timber.e(ie);;
}
Timber.d("Mobile Number: " + incomingNumber);
}
}
int transactionId = bundle.getInt("transactionId", -1);
Timber.d("transactionId " + transactionId);
int pduType = bundle.getInt("pduType", -1);
Timber.d("pduType " + pduType);
byte[] buffer2 = bundle.getByteArray("header");
if (buffer2 != null) {
String header = new String(buffer2);
Timber.d("header " + header);
}
List<MMSMessage> textMessages = MMSUtils.getMessagesFrom(context, intent); //meat of onReceive()
sendMessages(textMessages);
} else {
Timber.e("Invalid PUSH data");
}
}
}
}
我做错了什么?
答案 0 :(得分:0)
将以下内容添加到Manifest中的主要活动似乎解决了问题:
<activity
android:name="com.webnation.text2email.main.SMSEmailActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>