2012-11-29 39 views
0

我有困難接受在地圖 的形式短信我想,當收到消息出來alertdialog確定和取消時的地圖時,點擊好 幫我發送郵件,彈出地圖alertdialog

我的代碼

//SMSReceiver.java

public class SMSReceiver extends BroadcastReceiver 
{ 
    static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; 

    @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 += "Location " + " Longitude : " + lon + "\n Latitude : " + lat; 
       str += msgs[i].getMessageBody().toString(); 
       str += "\n";   
      } 

       String action = intent.getAction(); 
     if (ACTION.equals(action)) 
     { 
      //Start Activity here 
      Intent startIntent = new Intent(context, SMSNotif.class); 
        startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
        startIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
        String name = "pesan"; 
        String value = "str"; 
        startIntent.putExtra("pesan",String.valueOf(str)); 
        context.startActivity(startIntent); 

     }  
    } 
} 
} 

//messageNotif.java

public class messageNotif extends Activity 
{ 
private static final String LOG_TAG = "SMSReceiver"; 
public static final int NOTIFICATION_ID_RECEIVED = 0x1221; 
public Intent i; 
private String pesan ; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Bundle extras = getIntent().getExtras(); 
    pesan = String.valueOf(extras.getString("pesan")); 

    //---display the new SMS message--- 
    Toast.makeText(null,"budug"+pesan, Toast.LENGTH_LONG).show(); 

    // call displayAlert() here 
     displayAlert(); 
} 
    public void displayAlert() 
    { 
     AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("Rehere"); 
     builder.setMessage("Are you open in rehere?").setCancelable(
      false).setPositiveButton("Ok", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
       launchIntent(); 

       } 

       private void launchIntent() { 
        Intent myIntent = new Intent(getBaseContext(), My_Map.class);    
        startActivity(myIntent); 
       } 
      }).setNegativeButton("Cancel", 
      new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }); 
     AlertDialog alert = builder.create(); 
     alert.show(); 
    } 

} 
} 

//map.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/myLocationText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

    <com.google.android.maps.MapView 
     android:id="@+id/map" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:apiKey="0d8Ntrj9uYka52jVwlG4TacE1HwZB6YSxFF_YZA" 
     android:clickable="true" 
     android:enabled="true" /> 

</LinearLayout> 

什麼是錯我的代碼? 你能幫我嗎

+0

有人幫我 – Arrul

回答

0

1.Intent startIntent = new Intent(context,SMSNotif.class); 但public class messageNotif extends活動

2.Toast.makeText(null,「budug」+ pesan,Toast.LENGTH_LONG).show(); 第一個參數應該是這樣Toast.makeText(這一點,.....

3.startIntent.putExtra( 「pesan」,將String.valueOf(STR));

捆綁額外= getIntent()。 getExtras(); pesan =將String.valueOf(extras.getString( 「pesan」)); 這裏的捆綁額外爲null

pesan = getIntent()getStringExtra( 「pesan」)

4。 launchIntent();應在類中聲明

你可以重寫方法的代碼