| Author |
Message |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Tue Mar 17, 2009 6:50 pm Post subject: Queue and Display Call Log in a Simple List, Names Only |
|
|
I am trying to construct a simple app that allows me to see my call log, displaying names only, in a "simple_list_item_1". I am totally new to Java and Android and this is really the first step in creating my first app.
Here's what I've got (go easy, please):
Manifest:
| XML: | <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ipaulpro.calls"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name" android:debuggable="true">
<activity android:name=".Calls"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.READ_CONTACTS"></
uses-permission>
</manifest> |
Calls.java
| Java: | package com.ipaulpro.calls;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
public class Calls extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Cursor c = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI,
null, null, null,
android.provider.CallLog.Calls.DATE+ " DESC");
startManagingCursor(c);
ListAdapter adapter = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_1,
c,
new String[] {CallLog.Calls.CACHED_NAME},
new int[] {CallLog.Calls.MISSED_TYPE}
);
setListAdapter(adapter);
}
}
|
Main.xml
| XML: | <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView id="@+id/row_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout> |
So the app starts, but displays an empty list (with borders).
Any helps, tips, links would be very appreciated.
Thanks in advance.
Last edited by iPaul Pro on Wed Mar 25, 2009 7:36 pm; edited 1 time in total |
|
| Back to top |
|
 |
|
|
 |
iPaul Pro Developer

Joined: 15 Mar 2009 Posts: 33
|
Posted: Thu Mar 19, 2009 9:03 pm Post subject: |
|
|
Okay, so I've achieved my intended goal (the first step in my application).
I thought I'd share the code to output a simple list with cached names from the call log (no name displayed for UNKNOWN and PRIVATE numbers -- I'm working on that and will report when I figure it out - again, I'm a newb and know this can be achieved with an "if - then" statement - just don't know how to do it yet).
| Java: | import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;
public class Calls extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor c = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI,
null,
null,
null,
android.provider.CallLog.Calls.DATE+ " DESC");
startManagingCursor(c);
// Now create an adapter and set it to display using android.R.layout.simple_list_item_1
SimpleCursorAdapter calls = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_1,
c,
new String[] { android.provider.CallLog.Calls.CACHED_NAME },
new int[] { android.R.id.text1 });
setListAdapter(calls);
}
} |
There's no need to specify xml in your res/layout/ as we are using default Android styles.
The only change to the Manifest is adding the permission to read contact data (call log pulls from contacts)
Put
| XML: | <uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission> |
anywhere before or after the <application> tags.
And in case someone is wondering, here how you would output the cached name and number on a two-line list, using the "simple list 2" template.
| Java: | import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;
public class Calls extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor c = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI,
null,
null,
null,
android.provider.CallLog.Calls.DATE+ " DESC");
startManagingCursor(c);
// Now create an adapter and set it to display using android.R.layout.simple_list_item_2
SimpleCursorAdapter calls = new SimpleCursorAdapter(
this,
android.R.layout.simple_list_item_2,
c,
new String[] { android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.NUMBER },
new int[] { android.R.id.text1, android.R.id.text2 });
setListAdapter(calls);
}
} |
Hope that helps someone out there. I'll keep this thread updated with my related findings. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|