i work basic4android and i want to run a java code with JavaObject in it.
i want to get all contacts. my java code is :
#if java
import android.content.*;
import android.database.Cursor;
import android.provider.ContactsContract;
public String getall()
{
String res="";
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext())
{
String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
res = res + name + " , " + phoneNumber + "\n";
}
phones.close();
return res;
}
#end if
app runs but i get an error : java.lang.reflect.invocationtargetexception
please help me. thanks.
Add
<uses-permission android:name="android.permission.READ_CONTACTS" />
To your's AndroidManifest.xml file.