textview에 뿌려진 내폰번호를 string id=" " 안으로 가져오기

조회수 67회

public class MainActivity extends AppCompatActivity {

TextView  txtPhoneNo;
//manager
TelephonyManager telephonyManager;


TextView txtview;
phpdo task;


private static final int PERMISSION_REQUEST_CODE = 100;


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


    txtPhoneNo = (TextView) findViewById(R.id.txtPhoneNo);
    //manager
    telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    //통신사 전화번호 구하기

    txtPhoneNo.setText(getPhoneNumber());



    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            // 실행 코드
            moveTaskToBack(true); // 태스크를 백그라운드로 이동
            finishAndRemoveTask(); // 액티비티 종료 + 태스크 리스트에서 지우기
            android.os.Process.killProcess(android.os.Process.myPid()); // 앱 프로세스 종료

        }
    }, 1000000);

    String id = "휴대폰번호";


    task = new phpdo();
    txtview = (TextView) findViewById(R.id.txtView);
    task.execute(id);


}

@SuppressLint("HardwareIds")
public String getPhoneNumber() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_NUMBERS) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return null;
    }
    return
            telephonyManager.getLine1Number();
}






private class phpdo extends AsyncTask<String,Void,String> {

    protected void onPreExecute(){

    }
    @Override
    protected String doInBackground(String... arg0) {

        try {
            String id =  arg0[0];


            String link = "http://1111.co.kr/3333.php?cccc=" + id;
            URL url = new URL(link);
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(link));
            HttpResponse response = client.execute(request);
            BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

            StringBuffer sb = new StringBuffer("");
            String line = "";

            while ((line = in.readLine()) != null) {
                sb.append(line);
                break;
            }
            in.close();
            return sb.toString();
        } catch (Exception e) {
            return new String("Exception: " + e.getMessage());
        }

    }

    @Override
    protected void onPostExecute(String result){
        //txtview.setText("Login Successful");
        txtview.setText(result);
    }
}

위 소스는 어플이 실행되면 내 폰번호를 가져와서 txtPhoneNo 텍스트뷰에 내폰번호를 나타내주고 3333.php 파일로 전화번호를 전달하고 전화번호와 매칭된 이름값을 가져와서 textview 텍스트뷰에 나타내주는 소스입니다.

String id = "휴대폰번호"; <= 이부분에
String id = "01012345678"; 처럼 직접 입력을 해 놓고 빌드테스트를 하면 위 과정이 정상적으로 잘 작동 합니다...

txtPhoneNo.setText(getPhoneNumber()); <= 여기에 들어온 전화번호 값을

String id = " "; <== 따옴표 안에 위 전화번호 값이 들어 가게 하려면 어떻게 해야 할까요?

아니면 String id = " "; 는 무시하고 String link = "http://1111.co.kr/3333.php?cccc=" + id; 이 부분중에 id 부분에 핸드폰번호가 들어 가게 해도 됩니다.

고수님들 부탁드립니다

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)