1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Android: Fast Dialer pdf

6 204 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Ứng Dụng Gọi Điện
Trường học Trường Đại Học Khoa Học Tự Nhiên
Chuyên ngành Lập Trình Android
Thể loại Bài Tập
Năm xuất bản 2025
Thành phố Hồ Chí Minh
Định dạng
Số trang 6
Dung lượng 202,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Ứng dụng gọi điện Sau đây mình sẽ tạo ra và chạy thử 1 ứng dụng gọi điện nho nhỏ trên Android: 1/ Các bạn tạo 1 project như sau: Build Target: Android 2.2 Application Name: DialExample P

Trang 1

Ứng dụng gọi điện Sau đây mình sẽ tạo ra và chạy thử 1 ứng dụng gọi điện nho nhỏ trên Android:

1/ Các bạn tạo 1 project như sau:

Build Target: Android 2.2

Application Name: DialExample

Package Name: com.org DialExample

Activity Name: DialExample

Min SDK Version: 8

2/ Các bạn tạo giao diện và xử lý bằng cách code trực tiếp trên file DialExample.java như sau:

package com.org.DialExample;

import android.app.Activity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.LinearLayout;

public class DialExample extends Activity {

EditText mEditText_number = null;

LinearLayout mLinearLayout_no_button = null;

Trang 2

Button mButton_dial = null;

/** Called when the activity is first created */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mLinearLayout_no_button = new LinearLayout(this);

mEditText_number = new EditText(this);

mEditText_number.setText("01689938215");

mLinearLayout_no_button.addView(mEditText_number);

mButton_dial = new Button(this);

mButton_dial.setText("Goi !");

mLinearLayout_no_button.addView(mButton_dial);

mButton_dial.setOnClickListener(new View.OnClickListener() { public void onClick(View v)

{

performDial();

}

});

Trang 3

if (keyCode == KeyEvent.KEYCODE_CALL)

{

performDial();

return true;

}

else if(keyCode == KeyEvent.KEYCODE_BACK)

{

finish();

return true;

}

else

return false;

}

public void performDial(){

if(mEditText_number!=null){

try {

startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + mEditText_number.getText())));

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

Trang 4

Cuối cùng các bạn debug ứng dụng và sẽ đc như các hình sau:

Ban đầu:

Sau Khi bấm nút “Gọi”:

Trang 6

Mọi ý kiến đóng góp các bạn vui lòng post bài vào forum trang web

www.laptrinhdidong.vn Rất mong nhận đc sự phản hồi của các bạn Mình sẽ cập nhật trang web thường xuyên

Ngày đăng: 07/08/2014, 14:20

TỪ KHÓA LIÊN QUAN

w