-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialer.java
53 lines (47 loc) · 1.76 KB
/
dialer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.dialer;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button callBtn,saveBtn,deleteBtn;
EditText phone;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callBtn = findViewById(R.id.call);
saveBtn = findViewById(R.id.save);
deleteBtn = findViewById(R.id.delete);
phone = findViewById(R.id.num);
callBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String phoneNo = phone.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+phoneNo));
startActivity(intent);
}
});
saveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String phoneNo = phone.getText().toString();
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE,phoneNo);
startActivity(intent);
}
});
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
phone.setText("");
}
});
}
}