Note that there are some explanatory texts on larger screens.

plurals
  1. POModify first phone number and saved it android
    primarykey
    data
    text
    <p>I want to retrieve the first phone number using the code below, add a zero in front of that number and saved the phone number. I am new to this and up to now and the code below open the contact list, then the user select a phone number and the phone number is displayed as a toast. However, i want the first phone number in my contact list to get a zero in front and then get saved. I know i am not far from the solution but while am trying, it would be faster if i get your help. Thanks.</p> <p>public class MainActivity extends Activity {</p> <pre><code> public static final int PICK_CONTACT = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // this opens the activity. note the Intent.ACTION_GET_CONTENT // and the intent.setType ((Button)findViewById(R.id.btn_contacts)).setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // user BoD suggests using Intent.ACTION_PICK instead of .ACTION_GET_CONTENT to avoid the chooser Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // BoD con't: CONTENT_TYPE instead of CONTENT_ITEM_TYPE intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); startActivityForResult(intent, 1); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { Uri uri = data.getData(); if (uri != null) { Cursor c = null; try { c = getContentResolver().query(uri, new String[]{ ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.TYPE }, null, null, null); if (c != null &amp;&amp; c.moveToFirst()) { String number = c.getString(0); int type = c.getInt(1); showSelectedNumber(type, number); } } finally { if (c != null) { c.close(); } } } } } public void showSelectedNumber(int type, String number) { Toast.makeText(this, type + ": " + number, Toast.LENGTH_LONG).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload