1
我是android技術的新手。就在我開始學習之前的一個星期。我試圖用我的註冊手機號碼發送我的位置的詳細信息。它只在SONY手機上運行良好。誰能幫我。這是我正在使用的代碼。如何發送有關我的位置地址的短信android
private void SendSMsandGeocoder() {
Geocoder ageocoder=new Geocoder(myContext);
try {
TelephonyManager atele=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String adata=atele.getDeviceId();
AccountManager AAcm=AccountManager.get(myContext);
Account[] aAccarray=AAcm.getAccounts();
Log.e("account manager",aAccarray.toString());
for (Account ac : aAccarray) {
String acname = ac.name;
String actype = ac.type;
Log.e("acname",acname);
Log.e("actype", actype);
Log.e("account details",acname+actype);
myAcnameget= acname;
}
double mySourcelat =mygpsclass.Findlatitude();
double mySourcelng =mygpsclass.FindLongitude();
Log.e("Gps cordinates", mySourcelat+","+mySourcelng);
List<Address> aList=ageocoder.getFromLocation(mySourcelat, mySourcelng, 2);
String aPlacename=aList.get(0).getLocality();
Log.e("location name",aPlacename);
String aSublocality=aList.get(0).getSubLocality();
Log.e("Sub locality",aSublocality);
String mySourceplace=mySourcelat+","+mySourcelng;
String aaddress=aList.get(0).getFeatureName();
Log.e("feature name",aaddress);
String aaddress1=aList.get(0).getPostalCode();
Log.e("through fare",aaddress1);
String aAddressfull=aSublocality+","+aaddress+","+aPlacename+","+aaddress1;
String aSendmsgcontent="The User Of the IMEI no:"+adata+" was in Co-ordinates:" +mySourceplace+" and their address was "+aAddressfull+","+ myAcnameget;
Log.e("Full address With msg", aSendmsgcontent);
myHashmap=myDbclass.GetConDetails();
myCon1=myHashmap.get("Contact1");
Log.e("Contact 1",myCon1);
myCon2=myHashmap.get("Contact2");
Log.e("Contact 2",myCon2);
myCon3=myHashmap.get("Contact3");
Log.e("Contact 3",myCon3);
myCon4=myHashmap.get("Contact4");
Log.e("Contact 4",myCon4);
myCon5=myHashmap.get("Contact5");
Log.e("Contact 5",myCon5);
SmsManager aSms=SmsManager.getDefault();
aSms.sendTextMessage(myCon1, null,aSendmsgcontent, null, null);
aSms.sendTextMessage(myCon2, null,aSendmsgcontent, null, null);
aSms.sendTextMessage(myCon3, null,aSendmsgcontent, null, null);
aSms.sendTextMessage(myCon4, null,aSendmsgcontent, null, null);
aSms.sendTextMessage(myCon5, null,aSendmsgcontent, null, null);
} catch (Exception e) {
Log.e("sms", e.toString());
}
}
如果這沒有幫助請告訴我.. – Ajeet 2015-03-31 08:14:41
謝謝先生,它會工作。另一個更多的問題,而發送acount經理的細節和gps位置,它會顯示錯誤日誌:sms java.lang.nullpointerexception println需要消息。如何解決這個問題 – 2015-03-31 09:01:20
你需要把你的「消息(位置)字符串」放在smsManager.sendTextMessage(phoneNo,null,msg,null,null);味精變量。嘗試使用String msg = temp;裏面try {}。你可以標記這個答案爲勾號,它會幫助我:) – Ajeet 2015-03-31 09:04:09