如果从 LOCATION 字词开头,我想从任意数字中删除短信。我正在短信中接收来自客户的 Lat-Long ,并在地图上显示他的位置。但是,如果他的消息从单词位置开始,我想删除客户端消息
邮件格式
位置,纬度,经度
接收短信的方法
@Override
public void onReceive(Context context, Intent intent) {
if (BuildConfig.DEBUG)
Log.v("SMSReceiver: onReceive()" + intent);
SharedPreferences prefs=context.getSharedPreferences("smsReceiver", Context.MODE_PRIVATE);
String phone="";
// Gson gson = new Gson();
// String json = prefs.getString("myObject", "");
// DatabaseHandler db = gson.fromJson(json, DatabaseHandler.class);
DatabaseHandler db = new DatabaseHandler(context);
Cursor cursor = db.showAllData();
Cursor temp = cursor;
// geocoder = new Geocoder(context);
geocoder = new Geocoder(context, Locale.GERMAN);
SmsMessage[] arr = SmsPopupUtils.getMessagesFromIntent(intent);
if (arr != null) {
for (SmsMessage sms : arr) {
Log.v("number" + sms.getDisplayOriginatingAddress());
cursor = temp;
cursor.moveToFirst();
do {
phone = cursor.getString(0);
android.util.Log.d("Excepition", phone);
if (sms.getDisplayOriginatingAddress().equals(phone)) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.mipmap.smspopup_icon);
String data = getAddress(sms.getDisplayMessageBody());
mBuilder.setContentTitle("SMS Received From " + cursor.getString(1));
mBuilder.setContentText(data);
Intent resultIntent = new Intent(context, Location.class);
resultIntent.putExtra("phone", sms.getDisplayMessageBody());
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(111112, mBuilder.build());
}
}while (cursor.moveToNext());
}
}
}
从消息
获取 Lat-Long 和位置的代码 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
String stringFull = getIntent().getExtras().getString("phone");
String[] both = stringFull.split(",");
String location=both[0];
double lat = Double.parseDouble(both[1]);
double lon = Double.parseDouble(both[2]);
if(location.equals("Location")
{
/*
Code here to delete message if first word is location...
*/
}
}