1. Download our Official Android App: Forums for Android!

Unable to make call from my real device

Discussion in 'Android Apps & Games' started by ianni, Sep 20, 2017.

  1. ianni

    ianni Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Sep 20, 2017

    Sep 20, 2017
    1
    0
    5
    Hello everybody.I want some advice,i make a program on Android and i wanto to do this,i want to run the app on my real device wich is attach on Android Studio,show my contact list,and when i push a number to start calling.
    This is my code

    Code (Java):
    1. public class MainActivity extends AppCompatActivity {
    2.  
    3.     public static final int PICK_CONTACT_REQUEST = 1;
    4.     TextView contactNumber;
    5.  
    6.     @Override
    7.     protected void onCreate(Bundle savedInstanceState) {
    8.         super.onCreate(savedInstanceState);
    9.         setContentView(R.layout.activity_main);
    10.  
    11.         contactNumber = (TextView) findViewById(R.id.contactnumber);
    12.         Button buttonPickContact = (Button) findViewById(R.id.pickcontact);
    13.  
    14.         buttonPickContact.setOnClickListener(new View.OnClickListener() {
    15.             @Override
    16.             public void onClick(View view) {
    17.  
    18.                 pickContact();
    19.             }
    20.         });
    21.     }
    22.  
    23.  
    24.     private void pickContact() {
    25.  
    26.         Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
    27.         pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
    28.         startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);
    29.  
    30.     }
    31.  
    32.  
    33.     //==========================================================================================
    34.  
    35.     protected void onActivityResult(int requestCode, int resultCode, Intent data)
    36.     {
    37.  
    38.         if (requestCode == PICK_CONTACT_REQUEST) {
    39.  
    40.             if (resultCode == RESULT_OK) {
    41.  
    42.                 Uri contactUri = data.getData();
    43.  
    44.                 String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER};
    45.  
    46.                 Cursor cursor = getContentResolver()
    47.                         .query(contactUri, projection, null, null, null);
    48.                 cursor.moveToFirst();
    49.  
    50.                 int column = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
    51.                 String number = cursor.getString(column);
    52.  
    53.                //HERE IS THE PROBLEM,WHEN I HIT A NUMBER IT RETURNS TO THE STARTING SCREEN
    54.               //I TRY TO DO WITH INTENTS
    55.  
    56.               Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse(number));
    57.              
    58.              
    59.              if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) !=                          PackageManager.PERMISSION_GRANTED) {
    60.     // TODO: Consider calling
    61.     //    ActivityCompat#requestPermissions
    62.     // here to request the missing permissions, and then overriding
    63.     //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
    64.     //                                          int[] grantResults)
    65.     // to handle the case where the user grants the permission. See the documentation
    66.     // for ActivityCompat#requestPermissions for more details.
    67.    
    68. }
    69. startActivity(intent);
    70.             }
    71.         }
    72.     }
    73.  
    74.    
    75.    
    76. }
    Thank you very much for any sugestions
     

    Advertisement

Share This Page

Loading...