tworzę aplikację dzwoniącą. Próbuję użyć domyślnego numeru w ActionView i chcę przekazać numer telefonu komórkowego w przycisku połączenia komórkowego.
to jest mój kod: -
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);
}
Dziękuję za Twój czas.
Odpowiedzi:
1 dla odpowiedzi № 1Za pomocą następującego kodu możesz zadzwonić ACTION_CALL Intent
int Number = 0377778888;
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + number));
startActivity(callIntent);
musisz także dodać to uprawnienie do pliku AndroidManifest
<uses-permission android:name="android.permission.CALL_PHONE" />
1 dla odpowiedzi nr 2
Masz dwie opcje:
posługiwać się
Intent.ACTION_CALL
:Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + number.trim())); startActivity(intent);
To skutecznie zadzwoni do dostarczonego
number
numer telefonu. Pamiętaj tylko, że ta akcja wymagaandroid.permission.CALL_PHONE
pozwolenie w manifeście:<uses-permission android:name="android.permission.CALL_PHONE" />
posługiwać się
Intent.ACTION_DIAL
:Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:" + number.trim())); startActivity(intent);
Pokazuje widok dialera za pomocą
number
jest już wybrany, ale pozwala użytkownikowi zdecydować, czy faktycznie wykonać połączenie, czy nie. To robi nie wymagają dodatkowych uprawnień.
1 dla odpowiedzi nr 3
Wypróbuj ten kod Zmieniłem ten kod:
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);