Created
June 17, 2014 00:44
-
-
Save dant3/9ad7e55f36613184f06e to your computer and use it in GitHub Desktop.
Android Apis in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity | |
import android.widget.TextView | |
import android.os.Bundle | |
import android.provider.ContactsContract | |
import android.content.ContentResolver | |
import android.database.Cursor | |
import android.util.Log | |
class MainActivity extends Activity { | |
override def onCreate(savedState: Bundle) = { | |
super.onCreate(savedState) | |
val view = new TextView(this) | |
view.setText("Reading contacts...") | |
setContentView(view) | |
read() | |
} | |
private def read():Unit = { | |
val resolver: ContentResolver = getContentResolver | |
val cursor: Cursor = resolver.query(ContactsContract.Data.CONTENT_URI, | |
null, | |
ContactsContract.Data.MIMETYPE + "=?", | |
Array(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE), | |
ContactsContract.Data.CONTACT_ID) | |
var lineNumber: Long = 0 | |
while (cursor.moveToNext) { | |
val id: Long = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID)) | |
val name: String = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)) | |
val data1: String = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1)) | |
Log.e("CONTACTS", s"$lineNumber : $id name=$name, data1=$data1") | |
lineNumber = lineNumber + 1 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Activity; | |
import android.content.ContentResolver; | |
import android.database.Cursor; | |
import android.os.Bundle; | |
import android.provider.ContactsContract; | |
import android.util.Log; | |
import android.widget.TextView; | |
public class MainActivityJava extends Activity { | |
protected void onCreate(Bundle savedState) { | |
super.onCreate(savedState); | |
TextView view = new TextView(this); | |
view.setText("Reading contacts..."); | |
setContentView(view); | |
read(); | |
} | |
private void read() { | |
ContentResolver resolver = getContentResolver(); | |
Cursor cursor = resolver.query(ContactsContract.Data.CONTENT_URI, | |
null, | |
ContactsContract.Data.MIMETYPE + "=?", | |
new String[] {ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}, | |
ContactsContract.Data.CONTACT_ID); | |
long lineNumber = 0; | |
while (cursor.moveToNext()) { | |
long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID)); | |
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME)); | |
String data1 = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1)); | |
Log.e("CONTACTS", lineNumber + " : " + id + " name=" + name + ", data1=" + data1); | |
lineNumber = lineNumber + 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment