Sim Tracking in android
<p>I am doing a app on sim tracking but unable to get result</p>

<p>here is the main activity</p>

<pre><code>public class MainActivity extends Activity {

String FILENAME = "old_file.txt";
int simstatus;
String simNo;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

     TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        if (simstatus != TelephonyManager.SIM_STATE_ABSENT) {
            System.out.println("--------SIM Present:" + simstatus);
            simNo = tManager.getSimSerialNumber();
            FileOutputStream fos;
            try {
                fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
                fos.write(simNo.getBytes());
                System.out.println("---------Data written to files is:"
                        + simNo);
                fos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
</code></pre>

<p>Reciever </p>

<pre><code>public class SimDataReciever extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction()))  {   
            System.out.println("Reciever Started");
            Intent CompareSimServiceIntent = new Intent(context,demo.class); 
            context.startService(CompareSimServiceIntent);  
        }
    }
}
</code></pre>

<p>and the service..</p>

<pre><code>String FILENAME = "old_file.txt";

    @Override
    public IBinder onBind(Intent intent) {
        // TODO Auto-generated method stub
        return null;
    }

    public int onStartCommand(Intent intent, int flags, final int startId) {

         Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    //run your service

//                   Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
                    TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
                    try {
                        FileInputStream fis = openFileInput(FILENAME);
                        InputStreamReader in = new InputStreamReader(fis);
                        BufferedReader br = new BufferedReader(in);
                        String data = br.readLine();
                        System.out.println("---Data Read From File is:" + data);
                        String newsiminfo = tManager.getSimSerialNumber();
                        System.out.println("---New SIM no is:" + newsiminfo);
                        if (data.equals(tManager.getSimSerialNumber())) {
                            System.out.println("------Old sim Present:");
//                          Toast.makeText(this, "Old SIM", Toast.LENGTH_LONG).show();

                        } else {
//                          Toast.makeText(this, "New SIM", Toast.LENGTH_LONG).show();
                            SmsManager smsMngr = SmsManager.getDefault();
                            String destinationaddress = "8281306132";
                            String scAddress = null;
                            String text = "New Sim Is Inserted In Your Device";
                            PendingIntent sentIntent = null;
                            PendingIntent deliveryIntent = null;
                            smsMngr.sendTextMessage(destinationaddress, scAddress, text,
                                    sentIntent, deliveryIntent);
                            System.out.println("-----SMS Send");
                        }

                    } catch (Exception e) {

                    }
                }
            }, 1*60*1000);

        return startId;
    }

}
</code></pre>

<p>pls help me to find the solution....</p>
