मेरे पास एक ऐप है जिसमें उपयोगकर्ता के लिए एक संपर्क चुनने और ऐप के माध्यम से उस संपर्क को टेक्स्ट भेजने के लिए एक पहलू है। ऐप केवल कुछ संपर्कों के साथ काम करता है और दूसरों पर विफल रहता है। अधिक सटीक:Intent.ACTION_PICK कुछ संपर्कों के लिए खाली कर्सर देता है
जो संपर्क मैंने हाथ से अपनी संपर्क पुस्तक में दर्ज किया है, Intent.ACTION_PICK
को उन्हें ऐप में खोजने और उन्हें वापस करने में कोई परेशानी नहीं है, यानी cursor.moveToFirst()
सत्य है।
लेकिन फेसबुक द्वारा आयात किए गए संपर्क के लिए (मेरा फोन फेसबुक संपर्कों के साथ सिंक करने के लिए सेट है), मुझे संपर्क पर क्लिक करने के बाद निम्नलिखित android.database.CursorIndexOutOfBoundsException
मिलते हैं। मेरे पास एक चमकदार सवाल है: मैंने सचमुच संपर्क का चयन करने के बाद परिणाम आकार 0 क्यों दिया? cursor.moveToFirst()
क्यों झूठा है?
dispatchIntent:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
pickContactIntent.setType(Phone.CONTENT_TYPE); // Show user only contacts w/ phone numbers
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
onActivity परिणाम:
(requestCode == PICK_CONTACT_REQUEST) {
// Get the URI that points to the selected contact
Uri contactUri = data.getData();
// We only need the NUMBER column, because there will be only one row in the result
String[] projection = { Phone.NUMBER };
// Perform the query on the contact to get the NUMBER column
// We don't need a selection or sort order (there's only one result for the given URI)
// CAUTION: The query() method should be called from a separate thread to avoid blocking
// your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
// Consider using CursorLoader to perform the query.
Cursor cursor = getContentResolver()
.query(contactUri, projection, null, null, null);
cursor.moveToFirst();
// Retrieve the phone number from the NUMBER column
int column = cursor.getColumnIndex(Phone.NUMBER);
String number = cursor.getString(column);
//do work with number here ...
}
नोट: मैं संपर्कों को देखने के
...Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
05-15 17:57:04.741: E/AndroidRuntime(21301): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:418)
05-15 17:57:04.741: E/AndroidRuntime(21301): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
05-15 17:57:04.741: E/AndroidRuntime(21301): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
05-15 17:57:04.741: E/AndroidRuntime(21301): at android.database.CursorWrapper.getString(CursorWrapper.java:114)
05-15 17:57:04.741: E/AndroidRuntime(21301): at com.company.Game.SendTextActivity.onActivityResult(SendTextActivity.java:118)
05-15 17:57:04.741: E/AndroidRuntime(21301): at android.app.Activity.dispatchActivityResult(Activity.java:5436)
05-15 17:57:04.741: E/AndroidRuntime(21301): at android.app.ActivityThread.deliverResults(ActivityThread.java:3188)
05-15 17:57:04.741: E/AndroidRuntime(21301): ... 11 more
यहाँ मेरी कोड है। लेकिन जब मैं फेसबुक आयातित संपर्क का चयन करता हूं, तो मुझे दुर्घटना मिलती है।
Btw: http://developer.android.com/training/basics/intents/result.html
ध्यान दें कि फेसबुक संपर्कों के लिए 'cursor.moveToFirst()' झूठा रिटर्न देता है। मुझे अपवाद को पकड़ने जैसे बैंडएड में दिलचस्पी नहीं है। मुझे पता है कि 'कर्सर.मोव टू फर्स्ट() 'कैसे जांचें। मुझे यह जानने की ज़रूरत है कि उन संपर्कों के लिए संख्याएं कैसे प्राप्त करें। –
यह टिप्पणी आपके प्रश्न से संबंधित नहीं है ... चूंकि आप प्रक्षेपण का उपयोग कर रहे हैं, आपको कॉल करने की आवश्यकता नहीं है .getColumnIndex (...)। कॉलम इंडेक्स प्रक्षेपण स्ट्रिंग सरणी में उस कॉलम की अनुक्रमणिका से मेल खाएगा। – abh