Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to detect SIM change in android
    primarykey
    data
    text
    <p>Hi friends i am using the following code to detect SIM change but not able to get the result. Please suggest me where i am making the mistake.</p> <p>I am Using MainActivity.java class for Storing SIM msisdn. like this</p> <pre><code>public class MainActivity extends Activity { String FILENAME = "old_file.txt"; int simstatus; String msisdn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); simstatus = tManager.getSimState(); if (simstatus != TelephonyManager.SIM_STATE_ABSENT) { System.out.println("--------SIM Present:" + simstatus); msisdn = tManager.getLine1Number(); FileOutputStream fos; try { fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(msisdn.getBytes()); System.out.println("---------Data written to files is:" + msisdn); fos.close(); } catch (Exception e) { e.printStackTrace(); } } } </code></pre> <p>And for receiving the Reboot event i am using SIMTestReceiver class like this.</p> <pre><code>public class SIMTestReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) { Intent CompareSimServiceIntent = new Intent(context,TestDATAScreen.class); context.startService(CompareSimServiceIntent); } } </code></pre> <p>And for comparing the old SIM and New SIM i am using TestDATAScreen service class like this.</p> <pre><code>public class TestDATAScreen extends Service { String FILENAME = "old_file.txt"; @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public int onStartCommand(Intent intent, int flags, final int startId) { 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.getLine1Number(); System.out.println("---New SIM no is:" + newsiminfo); if (data.equals(tManager.getLine1Number())) { 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 = "8689908070"; 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) { } return startId; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload