Example usage for android.content Intent ACTION_CALL

List of usage examples for android.content Intent ACTION_CALL

Introduction

In this page you can find the example usage for android.content Intent ACTION_CALL.

Prototype

String ACTION_CALL

To view the source code for android.content Intent ACTION_CALL.

Click Source Link

Document

Activity Action: Perform a call to someone specified by the data.

Usage

From source file:com.arthackday.killerapp.GCMIntentService.java

@Override
protected void onMessage(Context ctxt, Intent message) {
    Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh GCMessage");
    Bundle extras = message.getExtras();

    /*//from  w  w  w.ja  v  a2  s .  c  om
     * TO DO! CHANGE WHAT THE MESSAGES DO!!
     */

    for (String key : extras.keySet()) {
        Log.i(getClass().getSimpleName(), String.format("onMessage: %s=%s", key, extras.getString(key)));

        if (key.equals(KillerConstants.EXTRA_KEY_AUDIO)) {
            Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh pushAudio");
            Intent i = new Intent();
            Log.i("REMOVE BEFORE COMMIT", extras.getString(key));

            Bundle bundle = new Bundle();
            //Add your data to bundle
            bundle.putString(KillerConstants.EXTRA_KEY_AUDIO, extras.getString(key));
            //Add the bundle to the intent
            i.putExtras(bundle);
            i.setClassName("com.arthackday.killerapp", "com.arthackday.killerapp.PushAudio");
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
        }

        if (key.equals(KillerConstants.EXTRA_KEY_PUSHCALL)) {
            Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh callnumber");
            String number = extras.getString(KillerConstants.EXTRA_KEY_PUSHCALL);
            String uri = "tel:" + number.trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
}

From source file:id.satusatudua.sigap.ui.fragment.ImportantContactFragment.java

private void onItemContactClicked(ImportantContact importantContact) {
    if (showFab) {
        startActivity(DetailContactActivity.generateIntent(getActivity(), importantContact));
    } else {/*from  w ww.  j ava  2 s .c  om*/
        Intent intent = new Intent(Intent.ACTION_CALL,
                Uri.parse("tel:" + importantContact.getPhoneNumber().trim()));
        startActivity(intent);
    }
}

From source file:id.satusatudua.sigap.ui.ProfileActivity.java

@OnClick(R.id.phone)
public void callPhone() {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + user.getPhoneNumber().trim()));
    startActivity(intent);/*from   www  .j  a va2 s  .co m*/
}

From source file:com.example.places.fragments.PlaceInfoFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    toolbar = (Toolbar) view.findViewById(R.id.place_details_toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayShowHomeEnabled(true);

    progressBar = (ProgressBar) view.findViewById(R.id.place_details_progress);
    coverView = (ImageView) view.findViewById(R.id.place_details_cover);
    recyclerView = (RecyclerView) view.findViewById(R.id.place_details_recyclerview);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    floatingActionButton = (FloatingActionButton) view.findViewById(R.id.place_details_actionbutton);
    floatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override/*w w w .  ja v  a 2s  .  c om*/
        public void onClick(View v) {
            String phoneNumber = place.get(Place.PHONE);
            if (phoneNumber != null) {
                String strippedNumber = PhoneNumberUtils.stripSeparators(phoneNumber);
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + strippedNumber));
                listener.onCallPhone(intent);
            }
        }
    });

    toolbar.setTitle(place.get(Place.NAME));
    int actionButtonVisibility = place.has(Place.PHONE) ? View.VISIBLE : View.GONE;
    floatingActionButton.setVisibility(actionButtonVisibility);

    fetchPlaceInfo();
}

From source file:com.example.android.phonecallingsample.MainActivity.java

/**
 * Uses an implicit intent to make the phone call.
 * Before calling, checks to see if permission is granted.
 *
 * @param view View (phone_icon) that was clicked.
 *///from   w  w w . j  a v a2 s .  com
public void callNumber(View view) {
    EditText editText = (EditText) findViewById(R.id.editText_main);
    // Use format with "tel:" and phone number to create phoneNumber.
    String phoneNumber = String.format("tel: %s", editText.getText().toString());
    // Log the concatenated phone number for dialing.
    Log.d(TAG, getString(R.string.dial_number) + phoneNumber);
    Toast.makeText(this, getString(R.string.dial_number) + phoneNumber, Toast.LENGTH_LONG).show();
    // Create the intent.
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    // Set the data for the intent as the phone number.
    callIntent.setData(Uri.parse(phoneNumber));
    // If package resolves to an app, check for phone permission,
    // and send intent.
    if (callIntent.resolveActivity(getPackageManager()) != null) {
        checkForPhonePermission();
        startActivity(callIntent);
    } else {
        Log.e(TAG, "Can't resolve app for ACTION_CALL Intent.");
    }
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view != null) {

        ViewGroup parent = (ViewGroup) view.getParent();
        if (parent != null)
            parent.removeView(view);//from   ww w . j a v  a2s.c o m

    }
    try {
        view = inflater.inflate(R.layout.fragment_time_estemet, container, false);
    } catch (InflateException e) {
    }
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);

    gps = new GPSTracker(getActivity());
    MyApplication.arrivedrivermarker = true;
    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Please wait...");
    progressDialog.setCancelable(false);

    mlinerlayoutbottom = (LinearLayout) view.findViewById(R.id.ll_bottom);
    mphone = (ImageView) view.findViewById(R.id.iv_phone);
    mphonenumber = (TextView) view.findViewById(R.id.tv_phonenumber);
    marrivaltime = (TextView) view.findViewById(R.id.tv_textarrival);
    mname = (TextView) view.findViewById(R.id.tv_name);
    mlicence = (TextView) view.findViewById(R.id.tv_licence);
    mtaximodel = (TextView) view.findViewById(R.id.tv_model);
    muserImage = (ImageView) view.findViewById(R.id.imageView_close);
    getLatLong();
    btnSplite = (Button) view.findViewById(R.id.btn_splite_rides);

    btnSplite.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent in = new Intent(getActivity(), SplitAddFrnd.class);
            startActivity(in);
        }
    });

    mphone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String uri = "tel:" + mphonenumber.getText().toString().trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            startActivity(intent);
        }
    });

    System.out.println("userId>>>>>>>>>>>>>>>>>>>>>" + mUserId);

    mname.setText(MyApplication.driverName);
    mlicence.setText(MyApplication.licenseId);
    mtaximodel.setText(MyApplication.vehicle);
    mphonenumber.setText(MyApplication.mobileNO);

    Picasso.with(getActivity()).load(MyApplication.imageUrl).error(R.mipmap.avtar).placeholder(R.mipmap.avtar)
            .into(muserImage);

    System.out.println("driverImageurl" + "chceck=" + MyApplication.imageUrl);

    mphonenumber.setText("Call To" + " " + MyApplication.driverName);

    final SinchClient sinchClient = Sinch.getSinchClientBuilder().context(getActivity()).userId(mUserId)
            .applicationKey("3b013f09-db1f-422e-ac7b-c6498e119612")
            .applicationSecret("LMhelEFYtUqms55VX1C7MQ==").environmentHost("sandbox.sinch.com").build();

    sinchClient.setSupportCalling(true);
    sinchClient.start();
    mphone.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (call == null) {
                if (MyApplication.mobileNO != null && !MyApplication.mobileNO.equals("")) {
                    call = sinchClient.getCallClient().callPhoneNumber("+" + MyApplication.mobileNO);
                    System.out.println("mobile_number" + MyApplication.mobileNO);
                    //call = sinchClient.getCallClient().callPhoneNumber("+918510834641");
                    try {
                        call.addCallListener(new SinchCallListener());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    mphonenumber.setText("Hang Up");
                }
            } else {
                call.hangup();
            }
        }
    });

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;
}

From source file:at.wada811.utils.IntentUtils.java

/**
 * ??Intent??/*from  w  w  w  .ja  v a 2 s  .  com*/
 *
 * @param tel
 */
public static Intent createCallIntent(String tel) {
    return new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + tel));
}

From source file:tk.wasdennnoch.androidn_ify.ui.emergency.preferences.ContactPreference.java

/**
 * Calls the contact.//  w ww .  j  av  a  2  s .  co  m
 */
public void callContact() {
    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + mContact.getPhoneNumber()));
    if (ActivityCompat.checkSelfPermission(getContext(),
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    getContext().startActivity(callIntent);
}

From source file:gxu.software_engineering.market.android.activity.ItemActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from   w w w  .  j  a v  a 2  s.  c  o m*/
        break;
    case R.id.edit:
        Intent intent = new Intent(this, UpdateItemActivity.class);
        intent.putExtra(C.ID, getIntent().getLongExtra(C.ID, -1));
        startActivity(intent);
        break;
    case R.id.call_seller:
        Cursor c = getContentResolver().query(Uri.parse(C.BASE_URI + C.USERS + "/" + this.uid),
                new String[] { C.user.CONTACT }, null, null, null);
        if (!c.moveToNext()) {
            Toast.makeText(this, R.string.contact_not_found, Toast.LENGTH_SHORT).show();
        } else {
            Intent call = new Intent(Intent.ACTION_CALL);
            Uri data = Uri.parse("tel:" + c.getString(0));
            call.setData(data);
            startActivity(call);
        }
        break;
    case R.id.sms_seller:
        Cursor _c = getContentResolver().query(Uri.parse(C.BASE_URI + C.USERS + "/" + this.uid),
                new String[] { C.user.CONTACT }, null, null, null);
        if (!_c.moveToNext()) {
            Toast.makeText(this, R.string.contact_not_found, Toast.LENGTH_SHORT).show();
        } else {
            Intent sms = new Intent(Intent.ACTION_SENDTO);
            Uri data = Uri.parse("smsto:" + _c.getString(0));
            sms.setData(data);
            startActivity(sms);
        }
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.phonecallingsamplechallenge.MainActivity.java

/**
 * Uses an implicit intent to make the phone call.
 * Before calling, checks to see if permission is granted.
 *
 * @param view View that was clicked./* w w  w  .ja  v a2  s .  c om*/
 */
public void callNumber(View view) {
    String normalizedPhoneNumber;
    // Find the editText_main view and assign it to editText.
    EditText editText = (EditText) findViewById(R.id.editText_main);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Log.d(TAG, "Running version earlier than Lollipop. Can't normalize number.");
        normalizedPhoneNumber = editText.getText().toString();
    } else {
        normalizedPhoneNumber = PhoneNumberUtils.normalizeNumber(editText.getText().toString());
    }
    // Use format with "tel:" and phone number to create phoneNumber.
    String phoneNumber = String.format("tel: %s", normalizedPhoneNumber);
    // Log the concatenated phone number for dialing.
    Log.d(TAG, getString(R.string.dial_number) + phoneNumber);
    Toast.makeText(this, getString(R.string.dial_number) + phoneNumber, Toast.LENGTH_LONG).show();
    // Create the intent.
    Intent callIntent = new Intent(Intent.ACTION_CALL);
    // Set the data for the intent as the phone number.
    callIntent.setData(Uri.parse(phoneNumber));
    // If package resolves to an app, check for phone permission,
    // and send intent.
    if (callIntent.resolveActivity(getPackageManager()) != null) {
        checkForPhonePermission();
        startActivity(callIntent);
    } else {
        Log.e(TAG, "Can't resolve app for ACTION_CALL Intent.");
    }
}