TQC-304 接收簡訊
這是TQC的304題,
程式碼為自行撰寫,
僅供參考。
主要練習接收簡訊 ,
注意AndroidManifest.xml file設定要對。
package COM.TQC.GDD03;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class GDD03 extends Activity
{
private TextView mTextView1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView1 = (TextView) findViewById(R.id.myTextView1);
mTextView1.setText("等待接收簡訊...");
}
}
package COM.TQC.GDD03 ;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class GDD03_SM_Receiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
// TODO Auto-generated method stub
//---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
自我LV~