2012-04-04 16 views
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); 

    } 
+0

この 'context.startActivity(i);'行にコメントする理由は? –

答えて

2

AlertActivityアクティビティの開始後にaddFlags(Intent.FLAG_ACTIVITY_NEW_TASK)を追加しています。このようにしてください:

Intent i=new Intent(context,AlertActivity.class); 

i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

context.startActivity(i); 
+0

非常にうまくいきました – venkyMCA

関連する問題