Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8387667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:16:35+00:00 2026-06-09T18:16:35+00:00

Hi friends i am using the following code to detect SIM change but not

  • 0

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.

I am Using MainActivity.java class for Storing SIM msisdn. like this

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();

        }
    }

}

And for receiving the Reboot event i am using SIMTestReceiver class like this.

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);
    }

}

And for comparing the old SIM and New SIM i am using TestDATAScreen service class like this.

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;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:16:37+00:00Added an answer on June 9, 2026 at 6:16 pm

    I found the solution. Actually comparing serial number using tManager.getSimSerialNumber() Solve my issue. AS There is no guaranteed result from tManager.getLine1Number()to this problem because the phone number is not physically stored on all SIM-cards, or broadcasted from the network to the phone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get Online Friends by using following code. protected void GetActiveFriends()
I am making a get friends network function using SQL. I used the following
friends, i am using following code to get GPS location it is causing two
Hi Friends i was using the following jquery,but it is not gaving an output
Friends, I'm populating a GridView in my asp.net application using following code. GridView grdExport
friends, i have created custom title bar using following titlebar.xml file with code <?xml
The following batch request for retrieve friends using the same app is not working:
I am using below code to get profile image of friends using Resfb. I
friends, i am using following code to display bitmap on screen and having next
friends, i am trying to check internetconnectivity in android and using following code final

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.