Note that there are some explanatory texts on larger screens.

plurals
  1. PONot fetching contact-clicking contact it shows application has stopped
    primarykey
    data
    text
    <p>I am using smsfunction to send an sms,i want to fetch contact list from my number,if i click edittext of phoneno it has to open contact list of my phone,and it has to fetch contact number whatever i am selecting and it has to send.</p> <p>Right now in emulator,it shows "SMS faild, please try again later!" if i use that in device,after clicking any contact,it show "Myapplication has stopped"</p> <p>Sendsmsactivity.java</p> <pre><code>public class SendSMSActivity extends Activity { public static final int RQS_PICKCONTACT = 1; Button buttonSend; //EditText textPhoneNo; EditText phoneNo; EditText textSMS; int columnIndex_number; static String stringNumber; String sms; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.about); buttonSend = (Button) findViewById(R.id.buttonSend); textSMS = (EditText) findViewById(R.id.editTextSMS); /*textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo); textPhoneNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); //Uri uri = Uri.parse("smsto:" + textPhoneNo); //Intent intent = new Intent(Intent.ACTION_SENDTO, uri); } });*/ phoneNo = (EditText)findViewById(R.id.phoneNo); phoneNo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub final Uri uriContact = ContactsContract.Contacts.CONTENT_URI; Intent intentPickContact = new Intent(Intent.ACTION_PICK, uriContact); startActivityForResult(intentPickContact, RQS_PICKCONTACT); } }); /*Bundle extras = getIntent().getExtras(); if(extras !=null) { String sms = extras.getString("firstKeyName"); }*/ Intent intent1= getIntent(); // gets the previously created intent final String firstKeyName = intent1.getStringExtra("firstKeyName"); textSMS.setText(firstKeyName); buttonSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //String phoneNo = textPhoneNo.getText().toString(); try { SmsManager smsManager = SmsManager.getDefault(); //String name = null; smsManager.sendTextMessage(stringNumber, null, firstKeyName, null, null); Toast.makeText(getApplicationContext(), "SMS Sent!", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS faild, please try again later!", Toast.LENGTH_LONG).show(); e.printStackTrace(); } finish(); } }); } /*@Override public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); switch (reqCode) { case (PICK_CONTACT): if (resultCode == Activity.RESULT_OK) { //Uri uri = Uri.parse("smsto:" + textPhoneNo); //Intent intent = new Intent(Intent.ACTION_SENDTO, uri); Uri contactData = data.getData(); Cursor c = managedQuery(contactData, null, null, null, null); if (c.moveToFirst()) { final String name = c.getString(c.getColumnIndexOrThrow(People.NAME)); textPhoneNo.setText(name); } } break; } }*/ protected void onActivityResult(int requestCode,int resultCode,Intent data) { if(resultCode == RESULT_OK) { if(requestCode == RQS_PICKCONTACT) { Uri returnUri = data.getData(); Cursor cursor = getContentResolver().query(returnUri, null, null, null, null); if(cursor.moveToNext()){ int columnIndex_ID = cursor.getColumnIndex(ContactsContract.Contacts._ID); String contactID = cursor.getString(columnIndex_ID); int columnIndex_HASPHONENUMBER = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER); final String stringHasPhoneNumber = cursor.getString(columnIndex_HASPHONENUMBER); if(stringHasPhoneNumber.equalsIgnoreCase("1")){ Cursor cursorNum = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactID,null,null); //Get the first phone number if(cursorNum.moveToNext()) { columnIndex_number = cursorNum.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); final String stringNumber = cursorNum.getString(columnIndex_number); phoneNo.setText(stringNumber); } }else{ phoneNo.setText("NO Phone Number"); } }else{ Toast.makeText(getApplicationContext(), "NO data!", Toast.LENGTH_LONG).show(); } } } } } </code></pre> <p>Its not fetching contact from myphone,is it having any error in my code.</p> <pre><code>Logcat error 06-07 10:32:03.543: E/AndroidRuntime(1015): FATAL EXCEPTION: main 06-07 10:32:03.543: E/AndroidRuntime(1015): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK dat=content://contacts } 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.app.Activity.startActivityForResult(Activity.java:3370) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.app.Activity.startActivityForResult(Activity.java:3331) 06-07 10:32:03.543: E/AndroidRuntime(1015): at com.example.jsonandroid.SendSMSActivity$1.onClick(SendSMSActivity.java:41) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.view.View.performClick(View.java:4202) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.view.View$PerformClick.run(View.java:17340) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.os.Handler.handleCallback(Handler.java:725) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.os.Handler.dispatchMessage(Handler.java:92) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.os.Looper.loop(Looper.java:137) 06-07 10:32:03.543: E/AndroidRuntime(1015): at android.app.ActivityThread.main(ActivityThread.java:5039) 06-07 10:32:03.543: E/AndroidRuntime(1015): at java.lang.reflect.Method.invokeNative(Native Method) 06-07 10:32:03.543: E/AndroidRuntime(1015): at java.lang.reflect.Method.invoke(Method.java:511) 06-07 10:32:03.543: E/AndroidRuntime(1015): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-07 10:32:03.543: E/AndroidRuntime(1015): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-07 10:32:03.543: E/AndroidRuntime(1015): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    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.
 

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