我只需要接收传入的SMS来处理它,但是没有从onRecieve方法调用任何东西。一切看起来还不错,但是当我收到短信时什么都没发生!
这是应用程序标记内的清单标记:
<receiver android:name="com.chargeirancell.key0098.view.RubinAppWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/rubinwidgetinfo" />
</receiver>
<receiver android:name="com.chargeirancell.key0098.RubinRecieveSMS">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
这里也是应用程序标记之外的权限:
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
这是我的接收器类:
public class RubinRecieveSMS extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("SMS", "HI");
if (ChargeApp.mShared.getBoolean("sms", true)) {
Log.i("SMS", "HI");
String number = "";
String message = "";
Bundle bundle = intent.getExtras();
if (bundle != null) {
try {
int i;
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] currentMessages = new SmsMessage[pdusObj.length];
for (i = 0; i < currentMessages.length; i++) {
currentMessages[i] = SmsMessage
.createFromPdu((byte[]) pdusObj[i]);
number = currentMessages[i].getOriginatingAddress();
message = message
+ currentMessages[i].getMessageBody();
}
String pin;
if (number.contains("3453")) {
pin = message.substring(message.indexOf("ز:"),
message.indexOf("ک")).replace("ز:", "");
Intent i1 = new Intent(context,
ActivityDialogCharge.class);
i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
i1.putExtra("pin", pin);
context.startActivity(i1);
} else if (number.contains("8801 9574")) {
pin = message.substring(message.indexOf("ز:"),
message.indexOf("ک")).replace("ز:", "");
Intent i1 = new Intent(context,
ActivityDialogCharge.class);
i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
i1.putExtra("pin", pin);
context.startActivity(i1);
}
} catch (Exception e) {
}
}
}
}
}
即使你好也没有打印在logCat中! 有人可以帮我吗?
答案 0 :(得分:-2)
将代码替换为manifest
文件:
<receiver android:name=".RubinRecieveSMS" android:exported="true" >
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>