在android中发送imsi和imei号码作为短信

时间:2014-09-11 05:50:16

标签: android

我必须将我的手机的imsi和imei号码发送到其他号码作为短信。现在我可以使用下面的代码

获取我的手机的imsi和imei
package com.example.phonenumber;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.widget.TextView;

public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Getting the Object of TelephonyManager 
TelephonyManager tManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);


    String Imei=tManager.getDeviceId();
    String Imsi=tManager.getSubscriberId();

    TextView i=(TextView)findViewById(R.id.imeino);//Getting the TextView to display IMEI number
    i.setText("IMEI number - "+Imei);//Displaying IMEI number

    TextView n=(TextView)findViewById(R.id.imsi);
    n.setText("IMSI number - "+Imsi);
}
 }

为了发送短信,代码是

package com.example.sms;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity {

Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button = (Button) findViewById(R.id.buttonSend);


    button.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v) {


            String phoneNo = "123456";
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNo, null, "Txt msg successfull", null, null);
            Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();


        }
    });


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

现在我如何整合这两个代码?我应该发送短信imsi和imei直接到123456或一些xxxx号码。请给我一个解决方案。

1 个答案:

答案 0 :(得分:0)

     button.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) {



                String phoneNo = "123456";
                TelephonyManager tManager=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);


               String Imei=tManager.getDeviceId();
              String Imsi=tManager.getSubscriberId();
 String getSimSerialNumber = telemamanger..getLine1Number();


                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(phoneNo, null, "IMEI number - "+Imei+" "IMSI number - "+Imsi+" My Number : " +getSimSerialNumber  , null, null);
                Toast.makeText(getApplicationContext(), "SMS Sent!",
                            Toast.LENGTH_LONG).show();


            }
        });



<uses-permission android:name="android.permission.READ_PHONE_STATE" />