是否可以在appWidget上接收短信?
我看到了android示例源(API演示)。
在API演示中, ExampleAppWidgetProvider 类扩展 AppWidgetProvider ,而非 活动
所以,我想不可能像这样注册SMS Receiver,
rcvIncoming = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("telephony", "SMS received");
Bundle data = intent.getExtras();
if (data != null) {
// SMS uses a data format known as a PDU
Object pdus[] = (Object[]) data.get("pdus");
String message = "New message:\n";
String sender = null;
for (Object pdu : pdus) {
SmsMessage part = SmsMessage.createFromPdu((byte[])pdu);
message += part.getDisplayMessageBody();
if (sender == null) {
sender = part.getDisplayOriginatingAddress();
}
}
Log.i(sender, message);
}
}
};
registerReceiver(rcvIncoming, new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
我的目标是在自定义appWidget上接收短信。
任何帮助都将不胜感激!!
答案 0 :(得分:1)
AppWidgetProvider是BroadcastReceiver的派生类。因此,您可以覆盖onReceive()来处理SMS消息。当然,您必须首先在清单中正确设置SMS_RECEIVED的意图过滤器。