0
我的應用程序接收到SMS並更改爲活動以在我的應用程序中顯示一個警告對話框。 Toast
運行良好,但不會改變活動。 onReceive()
接收包含電子郵件的SMS,並根據該電子郵件ID,我的應用程序搜索關聯的聯繫人號碼並將其發回回覆消息。BroadcastReceiver類別的開始意圖
public void onReceive(Context context, Intent intent)
{
// Get SMS map from Intent
Bundle extras = intent.getExtras();
String messages = "";
if (extras != null)
{
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get("pdus");
// Get ContentResolver object for pushing encrypted SMS to incoming folder
//ContentResolver contentResolver = context.getContentResolver();
for (int i = 0; i < smsExtra.length; ++i)
{
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
String body = sms.getMessageBody().toString();
String address = sms.getOriginatingAddress();
messages += "SMS from " + address + " :\n";
messages += body + "\n";
// Here you can add any your code to work with incoming SMS
// I added encrypting of all received SMS
}
// Display SMS message
Toast.makeText(context, messages, Toast.LENGTH_SHORT).show();
Intent i=new Intent(context,AlertActivity.class);
// context.startActivity(i);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
爲什麼你評論這個'context.startActivity(i);'line? – 2012-04-04 10:42:18