/ / absolvovanie hodnoty volanie-tlačidlo v android - android

odovzdávanie hodnoty call-button v android - android

Vytváram volajúcu aplikáciu. Snažím sa použiť predvolené číslo v actionView a chcem odovzdať mobilné číslo v mobilnom volacom tlačidle.

toto je môj kód: -

public void onClick(View arg0) {
// this is real calling number
long mobile = "tel:9999999999";
// this is default number.and show in textfield of calling.
Uri uri = Uri.parse("tel:+919910699440");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// here i want to pass real calling num in Button. so when i press the
//calling button . button will get mobile num but not show.

intent.setData(Uri.parse("tel:"+mobile));

startActivity(intent);


}

Ďakujem za Tvoj čas.

odpovede:

1 pre odpoveď č. 1

Pomocou nasledujúceho kódu môžete volať ACTION_CALL Intent

int Number = 0377778888;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + number));
startActivity(callIntent);

a musíte tiež pridať toto povolenie do súboru AndroidManifest

<uses-permission android:name="android.permission.CALL_PHONE" />

1 pre odpoveď č. 2

Máte dve možnosti:

  • použitie Intent.ACTION_CALL:

    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:" + number.trim()));
    startActivity(intent);
    

    To bude účinne volať dodávané number telefónne číslo. Len nezabudnite, že táto akcia vyžaduje android.permission.CALL_PHONE povolenie v manifeste:

    <uses-permission android:name="android.permission.CALL_PHONE" />
    
  • použitie Intent.ACTION_DIAL:

    Intent intent = new Intent(Intent.ACTION_DIAL);
    intent.setData(Uri.parse("tel:" + number.trim()));
    startActivity(intent);
    

    To ukazuje zobrazenie dialera pomocou number už volal, ale umožňuje užívateľovi rozhodnúť sa skutočne uskutočniť hovor alebo nie. To sa deje nie vyžadujú ďalšie povolenia.


1 pre odpoveď č. 3

Vyskúšajte tento kód Zmenil som tento kód:

 no=txt_no.getText().toString().trim();

String URI_TEL = "tel";
Uri uri = Uri.fromParts(URI_TEL, no, null);

Intent intent = new Intent(Intent.ACTION_CALL,uri);
//intent.setData(Uri.parse(no));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(intent);