我必須發送我的手機的imsi和imei號碼作爲短信的其他號碼。現在,我能夠使用下面的代碼發送imsi和imei號碼作爲短信在android
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?我應該將imsi和imei直接發送到123456或一些xxxx號碼。請給我一個解決方案。
hace此解決方案的工作原理? – 2014-09-11 06:10:37