// Path: app/src/main/java/com/yan/mobilesafe/Service/LocationService.java
// public class LocationService extends Service {
// 
//     private SharedPreferences sharedPreferences;
//     private LocationManager locationManager;
//     private MylocationListenter listener;
// 
//     @Nullable
//     @Override
//     public IBinder onBind(Intent intent) {
//         return null;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         sharedPreferences = getSharedPreferences("config", MODE_PRIVATE);
//         //获取位置
//         locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// 
//         Criteria criteria = new Criteria();
//         criteria.setCostAllowed(true); //是否获取付费
//         criteria.setAccuracy(Criteria.ACCURACY_FINE);
//         String bestProvider = locationManager.getBestProvider(criteria, true); //获取最佳位置提供者
// 
//         listener = new MylocationListenter();
//         locationManager.requestLocationUpdates(bestProvider,0,0,listener);  //启动获取位置
//     }
// 
//     class MylocationListenter implements LocationListener {
// 
//         //位置发生变化
//         @Override
//         public void onLocationChanged(Location location) {
//             //保存经纬度
//             sharedPreferences.edit().putString("location", "jing" +
//                     location.getLongitude() + ";" + "wei" + location.getLatitude()).apply();
// 
//             stopSelf();   //停掉service
// 
//         }
// 
//         @Override
//         public void onStatusChanged(String provider, int status, Bundle extras) {
// 
//         }
// 
//         @Override
//         public void onProviderEnabled(String provider) {
// 
//         }
// 
//         @Override
//         public void onProviderDisabled(String provider) {
// 
//         }
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         locationManager.removeUpdates(listener);
//     }
// }


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
import com.yan.mobilesafe.R;
import com.yan.mobilesafe.Service.LocationService;
package com.yan.mobilesafe.receiver;



/**
 * 短信拦截
 * Created by a7501 on 2015/11/25.
 */
public class SmsReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        Object[] objects = (Object[]) intent.getExtras().get("pdus");

        assert objects != null;
        for (Object object :objects){
            SmsMessage message = SmsMessage.createFromPdu((byte[]) object);
            String originatingAddress = message.getOriginatingAddress();  //获取短信来源号码
            String messageBody = message.getMessageBody(); //获取短信内容
            abortBroadcast();// 中断短信的传递, 从而系统短信app就收不到内容了
            Log.e("SmsReceiver",originatingAddress + ":" +messageBody);

            if ("#*alarm*#".equals(messageBody)){
                //播放报警音乐
                MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs);
                player.setVolume(1f,1f);
                player.setLooping(true);
                player.start();
            }else if ("#*location*#".equals(messageBody)) {

// Path: app/src/main/java/com/yan/mobilesafe/Service/LocationService.java
// public class LocationService extends Service {
// 
//     private SharedPreferences sharedPreferences;
//     private LocationManager locationManager;
//     private MylocationListenter listener;
// 
//     @Nullable
//     @Override
//     public IBinder onBind(Intent intent) {
//         return null;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         sharedPreferences = getSharedPreferences("config", MODE_PRIVATE);
//         //获取位置
//         locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// 
//         Criteria criteria = new Criteria();
//         criteria.setCostAllowed(true); //是否获取付费
//         criteria.setAccuracy(Criteria.ACCURACY_FINE);
//         String bestProvider = locationManager.getBestProvider(criteria, true); //获取最佳位置提供者
// 
//         listener = new MylocationListenter();
//         locationManager.requestLocationUpdates(bestProvider,0,0,listener);  //启动获取位置
//     }
// 
//     class MylocationListenter implements LocationListener {
// 
//         //位置发生变化
//         @Override
//         public void onLocationChanged(Location location) {
//             //保存经纬度
//             sharedPreferences.edit().putString("location", "jing" +
//                     location.getLongitude() + ";" + "wei" + location.getLatitude()).apply();
// 
//             stopSelf();   //停掉service
// 
//         }
// 
//         @Override
//         public void onStatusChanged(String provider, int status, Bundle extras) {
// 
//         }
// 
//         @Override
//         public void onProviderEnabled(String provider) {
// 
//         }
// 
//         @Override
//         public void onProviderDisabled(String provider) {
// 
//         }
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         locationManager.removeUpdates(listener);
//     }
// }


// Path: app/src/main/java/com/yan/mobilesafe/receiver/SmsReceiver.java
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.util.Log;
import com.yan.mobilesafe.R;
import com.yan.mobilesafe.Service.LocationService;

package com.yan.mobilesafe.receiver;



/**
 * 短信拦截
 * Created by a7501 on 2015/11/25.
 */
public class SmsReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        Object[] objects = (Object[]) intent.getExtras().get("pdus");

        assert objects != null;
        for (Object object :objects){
            SmsMessage message = SmsMessage.createFromPdu((byte[]) object);
            String originatingAddress = message.getOriginatingAddress();  //获取短信来源号码
            String messageBody = message.getMessageBody(); //获取短信内容
            abortBroadcast();// 中断短信的传递, 从而系统短信app就收不到内容了
            Log.e("SmsReceiver",originatingAddress + ":" +messageBody);

            if ("#*alarm*#".equals(messageBody)){
                //播放报警音乐
                MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs);
                player.setVolume(1f,1f);
                player.setLooping(true);
                player.start();
            }else if ("#*location*#".equals(messageBody)) {

                context.startService(new Intent(context, LocationService.class));