1

データベース sqlite から電話をかけることができません。その方法を教えてください。このアクティビティのリストを選択すると、番号をダイヤルできません。データベースは作成されましたが、電話番号がアクティブではありません。助けてください。これは私のプロジェクトです:

public class HospitalP extends ListActivity {

private String[] dataTempat = null;

DatabaseHandler db = new DatabaseHandler(this);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView(R.layout.tampilphone);

    Log.d("Insert: ", "Inserting ..");
    db.addContact(new Contact("RUMAH SAKIT JOGJA INTERNATIONAL HOSPITAL",
            "02744463535"));
    db.addContact(new Contact("RUMAH SAKIT Dr SARDJITO", "0274587333"));
    db.addContact(new Contact("RUMAH SAKIT BETHESDA", "0274562246"));
    db.addContact(new Contact("RUMAH SAKIT UMUM PKU MUHAMADIYAH",
            "0274512653"));
    db.addContact(new Contact("RUMAH SAKIT ISLAM HIDAYATULAH", "0274389194"));
    db.addContact(new Contact("RUMAH SAKIT UMUM DAERAH KOTA YOGYAKARTA",
            "0274371195"));
    db.addContact(new Contact("BALAI PENGOBATAN PARU PARU", "0274374722"));
    db.addContact(new Contact("CITRA MEDIKA", "0274387775"));
    db.addContact(new Contact(
            "RUMAH SAKIT ANGKUTAN UDARA Dr S HARDJOLUKITO", "0274564467"));
    db.addContact(new Contact("RUMAH SAKIT BAKTI IBU", "0274383008"));
    db.addContact(new Contact("RUMAH SAKIT SAKINA IDAMAN", "0274582039"));
    db.addContact(new Contact("RUMAH SAKIT DKT", "0274555402"));
    db.addContact(new Contact("RUMAH SAKIT IBU DAN ANAK PURA IBUNDA",
            "0274514784"));
    db.addContact(new Contact("RUMAH SAKIT ISLAM AT TUROTS AL ISLAMI",
            "0274793823"));
    db.addContact(new Contact("RUMAH SAKIT KHUSUS ANAK EMPAT LIMA",
            "0274376962"));
    db.addContact(new Contact("RUMAH SAKIT KHUSUS BEDAH SOEDIRMAN",
            "0274589090"));
    db.addContact(new Contact("RUMAH SAKIT KHUSUS PURI NIRMALA",
            "0274515255"));
    db.addContact(new Contact("RUMAH SAKIT LUDIRA HUSADA TAMA",
            "0274620373"));
    db.addContact(new Contact("RUMAH SAKIT MATA DOKTER YAP", "0274584423"));
    db.addContact(new Contact("RUMAH SAKIT PATMASURI", "0274418007"));
    db.addContact(new Contact("RUMAH SAKIT PERMATA BUNDA", "0274376092"));

    Log.d("Reading: ", "Reading all contacts..");
    List<Contact> contacts = db.getAllContacts();

    dataTempat = new String[contacts.size()];
    int i = 0;
    for (Contact cn : contacts) {
        String log = "Id: " + cn.getID() + " ,Name: " + cn.getName()
                + " ,Phone: " + cn.getPhoneNumber();
        Log.d("Name: ", log);
        dataTempat[i] = cn.getName();
        i++;


    }
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, dataTempat);
    setListAdapter(adapter);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Object o = this.getListAdapter().getItem(position);
    String pilihan = o.toString();

    callRumahsakit(pilihan);
    // try {
    // Intent intent = new Intent(Intent.ACTION_CALL);
    // intent.setData(Uri.parse("telp:" + o.));
    // startActivity(intent);
    // } catch (Exception e) {
    // e.printStackTrace();
    //
    // }
}

private void callRumahsakit(String pilihan) {
    try {

        Contact cn = new Contact();
        String phone_number = "";

        for (int i = 0; i < dataTempat.length; i++) {
            if (pilihan.equals(dataTempat[i])) {
                phone_number = cn.getPhoneNumber();

            }
        }
        if (phone_number.equals("")) {
            Toast.makeText(this, "Rumah Sakit tidak terdaftar",
                    Toast.LENGTH_LONG).show();

            return;
        } else {

            Toast.makeText(this, phone_number, Toast.LENGTH_LONG).show();

            Intent callIntent = new Intent(Intent.ACTION_CALL,
                    Uri.parse("tel:" + phone_number));
            // callIntent.setData(Uri.parse("tel:" + phone_number));

            startActivity(callIntent);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // TODO: handle exception
    }
}

}

4

0 に答える 0