2
我有一個BroadCastReciver在我的應用程序,它監聽傳入的短信。 我想在短信收到時,應用程序通過意向打開谷歌地圖。這是我的代碼,但我不知道我的錯誤在哪裏。 感謝您的幫助。意圖谷歌地圖不工作
BroadcastReciver.class:
public class IncomingSms extends BroadcastReceiver {
// Get the object of SmsManager
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent) {
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try {
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
startAct(message, context);
} // end for loop
} // bundle is null
} catch (Exception e) {
Log.e("SmsReceiver", "Exception smsReceiver" + e);
}
}
private void startAct(String message, Context con) {
double Mylatitude = 12;
double Mylongitude = 11;
GPSTracker tracker = new GPSTracker(con);
if (tracker.canGetLocation()) {
Mylatitude = tracker.getLatitude();
Mylongitude = tracker.getLongitude();
}
String location = message;
String ACC_lat = location.substring(0, location.indexOf(","));
String ACC_lang = location.substring(location.indexOf(",") + 1, location.length());
Toast.makeText(con, ACC_lang + "^" + ACC_lat, Toast.LENGTH_LONG).show();
Intent mapIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=" + Mylatitude + "," + Mylongitude + "&daddr=" + ACC_lat + "," + ACC_lang));
con.startActivity(mapIntent);
}
我也manifest.xml
文件
所以,你檢查,你已經改正緯度,經度,ACC_lat和ACC_lang? –
如果可能的話打印日誌。你在哪裏遇到問題?你使用的是androidM嗎? – Drv