メッセージが受信されたときに必要なマップの形式でテキスト メッセージを受信するのが困難でした
私のコード
//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>
私のコードの何が問題になっていますか?? 手伝っていただけませんか