检索电话号码

时间:2012-04-23 03:38:18

标签: android android-contacts phone-number

我的应用程序安装在哪里,我想检索该手机的电话号码,然后将其发布到服务器上。这可能吗?

TelephonyManager tMgr = (TelephonyManager)mAppContext.getSystemService(
    Context.TELEPHONY_SERVICE); 
mPhoneNumber = tMgr.getLine1Number(); 

这会告诉我安装我的应用程序的号码吗?

3 个答案:

答案 0 :(得分:1)

检索电话号码后,您只需通过请求即可将其发送至服务器。

Request request = new Request("your-server/your-file?your-parameters);

答案 1 :(得分:0)

为什么需要查看电话号码?但还有一种方法是检查SIM卡号码。

答案 2 :(得分:0)

这个编程对我有用

我认为这会对你有所帮助....

import android.app.Activity;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

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

    Button tmpbtn = (Button) findViewById(R.id.button1);
    tmpbtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
             TelephonyManager telMgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
            Toast toast = Toast.makeText(getApplicationContext(), "Mobile Number : "+ telMgr.getLine1Number(), Toast.LENGTH_SHORT);
            toast.show();
            toast = Toast.makeText(getApplicationContext(), "Sim Serial Number : "+ telMgr.getSimSerialNumber(), Toast.LENGTH_LONG);
            toast.show();
        }
    });
}
}

此外,你必须在清单

中添加权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>