我想从android广播接收器中的textview获取实例以接收短信。我想在 textview 中显示短信并从“textview.settext("SmsContentEtc")”中使用,但是因为我在课堂上使用 creat 方法,所以我可以从 textview 获取实例!!!!
public class SmsReceiver extends BroadcastReceiver
{
private TextView txtshow;
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n"; `enter code here`
}
//---display the new SMS message---
//Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
txtshow.setText("smsContentEtc");
}
}
}