Saturday, 21 April 2012

Conference Dialing in Android


package com.confdial.android;


import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;


import com.confdial.android.DBHelper.ContactTable;


public class ViewDetailsActivity extends ListActivity {
Cursor cursor;
ContactDataSource datasource;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
datasource = new ContactDataSource(this);
datasource.open();
cursor = datasource.getAllContacts(this);

String[] from = new String[] { ContactTable.NAME , ContactTable.CONTACTS };
int[] to = new int[] { R.id.name, R.id.contacts };

ListAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor,
from, to);
setListAdapter(mAdapter);


final ListView lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {


@Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
TextView tv = (TextView) view.findViewById(R.id.contacts);
String contacts = tv.getText().toString();


String split = "#";
String[] contactArr = contacts.split(split);
String[] mobileNumbers = new String[contactArr.length/2];
int[] delayTime = new int[contactArr.length/2];
int j = 0;

for (int i = 0; i < contactArr.length; i++) {
if (i % 2 == 0) {
mobileNumbers[j] = contactArr[i];
} else {
delayTime[j] = Integer.parseInt(contactArr[i]);
j++;
}
}

Intent callIntent = new Intent(Intent.ACTION_CALL);
String phno;

try {
for (int i = 0; i < mobileNumbers.length; i++) {
Log.d("ViewDetailsActivity********* ", mobileNumbers[i]);
phno = "tel:" + mobileNumbers[i];
callIntent.setData(Uri.parse(phno));
startActivity(callIntent);


Thread.sleep(5000);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}


@Override
protected void onPause() {
datasource.close();
super.onPause();
}


@Override
protected void onResume() {
datasource.open();
super.onResume();
}


}

No comments:

Post a Comment