私は自分の位置(経度と緯度)を他人に送信する必要があるアプリケーションを持っています。私はどこかで自分の位置(経度と緯度)を取得し、返信SMSにテキストとして入れます他の人にそれを送信します。しかし、今私は私の場所を取得し、返信SMSのテキストとして配置する方法の問題に直面している今私は他からSMSを受信して返信メッセージを送信するコードを書いている私の場所を取得してテキストメッセージとして入力する方法を教えてもらえますか?ここで私の場所(経度と緯度)を他人に返信する方法は?
は、応答メッセージを送信するために私のコードです:
ます。public void onReceive(コンテキストコンテキスト、テントの意図){
Intent m=new Intent(context, ReceivelocationActivity.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, m, 0);
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
String str2="";
String str3="";
String autoReplyToken = "Request_Accepted";
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();
str2=msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getMessageBody().toString();
str3=msgs[i].getMessageBody().toString();
str += "\n";
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
SmsManager sms = SmsManager.getDefault();
boolean isAutoReply = str3.startsWith(autoReplyToken);
/* As suggested by Dan J */
Criteria hdCrit = new Criteria();
hdCrit.setAccuracy(Criteria.ACCURACY_COARSE);
hdCrit.setAltitudeRequired(false);
hdCrit.setBearingRequired(false);
hdCrit.setCostAllowed(true);
hdCrit.setPowerRequirement(Criteria.POWER_LOW);
hdLocMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
hdLocProvider = hdLocMgr.getBestProvider(hdCrit, true);
Location location = hdLocMgr.getLastKnownLocation(hdLocProvider);
Double dlat = location.getLatitude();
Double dlon = location.getLongitude();
String msg = dlat + "," + dlon ;
/* As suggested by Dan J */
if (!isAutoReply) {
String autoReplyText = autoReplyToken + msg;
sms.sendTextMessage(str2, null, autoReplyText, pi, null);
}
}
}
は誰がどのように代わり、「MSG」変数に実際の場所を送信する方法を教えてもらえます文字列 "location"の。任意のアイデアを持つ誰も私に教えてください?前もって感謝します。
でも、私はこの質問の答えを知りたいのですが、救助に来ることができる経験豊富な人がいるかどうかを見てみましょう。 –
あなたはまだ場所を取得する方法を考え出しましたか?この後、ロケーションオブジェクトから取得した番号を渡すことができますhttp://developer.android.com/guide/topics/location/obtaining-user-location.html –
私はDan Jの提案に従って試してみましたが、私のコードの追加が、今でもコンパイルされていません。何が起こっているのかわからなければ、私に提案してください。 –