TQC-302 接收簡訊,同時呼叫另一個Activity

TQC-302 接收簡訊,同時呼叫另一個Activity

這是TQC的302題,

程式碼為自行撰寫,

僅供參考。

 

主要練習接收簡訊,

同時呼叫另一個Activity。

而SMSreceiver記得設定addflag,不然不會成功

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

 





    
        
            
                
                
            
        
         

	   
             
                 
             
        

    
    
    
 

package COM.TQC.GDD03;

import android.app.Activity;
import android.os.Bundle;

public class GDD03 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

 


package COM.TQC.GDD03;

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;


public class SMSreceiver extends BroadcastReceiver {
	  
	
	
	 private static final String mACTION = "android.provider.Telephony.SMS_RECEIVED";
	  int sms_acc = 0;

	  public void onReceive(Context paramContext, Intent paramIntent)
	  {
	    if (!paramIntent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
	      return;
	    
	    Intent intent = new Intent(paramContext, Image.class);
	    Bundle localBundle = new Bundle();
	    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	   
	    paramContext.startActivity(intent);
	    
	    /*
	    Intent localIntent1 = new Intent(paramContext, Image.class);
	    Bundle localBundle = new Bundle();
	    Intent localIntent2 = localIntent1.putExtras(localBundle);
	    Intent localIntent3 = localIntent1.addFlags(268435456);
	    paramContext.startActivity(localIntent1);
	    paramContext.startActivity(localIntent1);
		*/
		  
		
        Toast.makeText(paramContext, "OK", Toast.LENGTH_SHORT).show();


	  }
}

 


package COM.TQC.GDD03;

import android.app.Activity;
import android.os.Bundle;

public class Image extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.image);
    }
}

 

 

自我LV~