Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Getting the contact's phone number

  • Loading branch information...
commit 07c8fc6edc803ee7d1b11fb110a21e348e8f1611 1 parent df8d685
@mike-burns mike-burns authored
View
1  AndroidManifest.xml
@@ -44,4 +44,5 @@
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
+ <uses-permission android:name="android.permission.INTERNET" />
</manifest>
View
5 src/com/matthoran/operator/MyContacts.java
@@ -33,6 +33,7 @@ public void onCreate(Bundle savedInstanceState)
setContentView(R.layout.my_contacts);
mContactList = (ListView) findViewById(R.id.contactList);
+ registerWithServer();
populateContactList();
mContactList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@@ -52,6 +53,10 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
}
});
}
+
+ private void registerWithServer() {
+
+ }
private void populateContactList() {
Cursor cursor = getContacts();
View
19 src/com/matthoran/operator/RefreshContacts.java
@@ -7,12 +7,13 @@
import org.apache.http.HttpStatus;
import org.apache.http.HttpResponse;
import org.apache.http.HttpEntity;
+import java.io.InputStream;
import android.util.Log;
class RefreshContacts extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
- return "Hello, world!";
+ return refreshContacts("http://operator.mike-burns.com/contacts_list/" + params[0]);
}
@Override
@@ -28,9 +29,25 @@ private String refreshContacts(String url) {
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("OSHI~", "Error" + statusCode + " while blah.");
+ return null;
}
final HttpEntity entity = response.getEntity();
+
+ if (entity != null) {
+ InputStream inputStream = null;
+ try {
+ inputStream = entity.getContent();
+ return inputStream.toString();
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ entity.consumeContent();
+ }
+ }
+
+
} catch (Exception e) {
getRequest.abort();
} finally {
View
32 src/com/matthoran/operator/TheirContacts.java
@@ -1,12 +1,12 @@
package com.matthoran.operator;
import android.app.Activity;
-import android.os.Bundle;
import android.content.Intent;
-import android.util.Log;
-import android.provider.ContactsContract;
-import android.net.Uri;
import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.provider.ContactsContract;
+import android.util.Log;
import android.widget.TextView;
public class TheirContacts extends Activity {
@@ -23,18 +23,18 @@ public void onCreate(Bundle savedInstanceState) {
TextView tv = (TextView) findViewById(R.id.theirContactsText);
if (cursor.moveToFirst()) {
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Data._ID));
- Cursor phones = getContentResolver().query(
- ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
- null,
- ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,
- null, null);
- while (phones.moveToNext()) {
- String phoneNumber = phones.getString(
- phones.getColumnIndex(
- ContactsContract.CommonDataKinds.Phone.NUMBER));
- tv.setText(phoneNumber);
- }
-
+ Cursor phones = getContentResolver().query(
+ ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
+ null,
+ ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,
+ null, null);
+ while (phones.moveToNext()) {
+ String phoneNumber = phones.getString(
+ phones.getColumnIndex(
+ ContactsContract.CommonDataKinds.Phone.NUMBER));
+ RefreshContacts contactRefresher = new RefreshContacts();
+ contactRefresher.execute(phoneNumber);
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.