-10

Where my application is installed I want to retrieve the phone number of that phone and then post it on the server. Is this possible?

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

will this get me the number where my app is installed..?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 2
    Yes, it is possible. What have you tried? Google is your friend. – Cristian Apr 23 '12 at 03:40
  • can you help me with that.. the code part.. – Radha Kumar Apr 23 '12 at 03:41
  • 1
    People will only put effort into responses if you put effort into your question. Requests to write code your code will probably be ignored, requests for help in a specific area or a specific sample would have a better chance of response. – David O'Meara Apr 23 '12 at 04:00
  • 'TelephonyManager tMgr =(TelephonyManager)mAppContext.getSystemService(Context.TELEPHONY_SERVICE); mPhoneNumber = tMgr.getLine1Number(); ' will this get me the number where the app is installed..? – Radha Kumar Apr 23 '12 at 04:07

3 Answers3

1

After retrieving the phone number, you can just send it to the server via Request.

Request request = new Request("your-server/your-file?your-parameters);
RThomas
  • 10,702
  • 2
  • 48
  • 61
113408
  • 3,364
  • 6
  • 27
  • 54
0

Why do you need to check the Phone Number? But one more way is there you can check sim card number.

Oleksi
  • 12,947
  • 4
  • 56
  • 80
Naresh
  • 31
  • 1
  • 5
  • after getting sim card number u can check whether that is ur sim or new sim, based on that u can do. – Naresh Apr 23 '12 at 03:44
  • Making an application where i will be needing the phone number where my application will be installed. how do i do it with the sim card numkber..? – Radha Kumar Apr 23 '12 at 03:44
  • Why do you need the phone number? It's not a good way to identify a device and has big security/privacy concerns. Down vote because your questions are poor, you haven't thought about this and you expect other people to do the work for you. Have you tried flower arranging? – Simon Apr 23 '12 at 06:43
  • r u got ans for ur question or u need sample code for checking sim number? – Naresh Apr 25 '12 at 07:34
0

this prog is working for me

i think this will help u ....

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

Also u have to add permission in manifest

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Naresh
  • 31
  • 1
  • 5