Mam ImageButton, który wyzwala zamiar wywołania. Chcę wiedzieć, czy możliwe jest przekazanie 2 numerów jako danych, aby po dotknięciu przycisku automatycznie otworzyło się wyskakujące okienko, które pozwala wybrać numer, pod który chcesz zadzwonić. Powinno to być domyślne zachowanie Androida dla Twoich kontaktów, jeśli masz więcej niż jeden numer powiązany z kontaktem, do którego próbujesz zadzwonić, daje to opcje.
Mój kod jest taki:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("1234567890"));
startActivity(callIntent);
Próbowałem wstawić wiele liczb oddzielonych średnikami, ale nie działa:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("1234567890;0987654321"));
startActivity(callIntent);
Czy ktoś ma na to rozwiązanie?
Dzięki Manuel.
2 odpowiedzi
Nie sądzę, że programowo istnieje coś takiego.
Ale możesz spróbować czegoś takiego, po kliknięciu przycisku obrazu:
1) Jeśli tylko 1 cyfra, użyj kodu, który napisałeś.
2) Jeśli wiele numerów, otwórz okno dialogowe (musisz to wszystko utworzyć samodzielnie) i pozwól użytkownikowi wybrać numer, a następnie przekieruj numer do swojego kodu
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
attachUi();
//getPattern();
}
private void attachUi() {
tv = (TextView) findViewById(R.id.textview);
tv.setOnClickListener(clk);
}
private View.OnClickListener clk = new View.OnClickListener() {
@Override
public void onClick(View view) {
gotoCall();
}
};
private void gotoCall() {
ArrayList<String> list = new ArrayList<String>();
list.add("08698511503");
list.add("07666175151");
list.add("0548554552");
TelephonyManager TelephonyMgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
TelephonyMgr.listen(new PhoneCallListener(this, list), PhoneStateListener.LISTEN_CALL_STATE);
if (ActivityCompat.checkSelfPermission(this, 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;
}
//startActivity(callIntent);
}
}
// create new class
class PhoneCallListener extends PhoneStateListener {
int count = 0;
Context context;
ArrayList<String> list;
public PhoneCallListener(MainActivity mainActivity, ArrayList<String> list) {
this.context = mainActivity;
this.list = list;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
Log.v(this.getClass().getSimpleName(), "List Size ::" + list);
switch (state) {
case TelephonyManager.CALL_STATE_RINGING:
Log.v(this.getClass().getSimpleName(), "Inside Ringing State::");
break;
case TelephonyManager.CALL_STATE_IDLE:
String phone_number = null;
Log.v(this.getClass().getSimpleName(), "Inside Idle State::");
if (list.size() > count) {
phone_number = list.get(count);
count++;
}
if (phone_number != null) {
nextCalling(phone_number);
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Log.v(this.getClass().getSimpleName(), "Inside OFFHOOK State::");
break;
default:
break;
}
}
private void nextCalling(String phone_number) {
Intent callIntent1 = new Intent(Intent.ACTION_CALL);
callIntent1.setData(Uri.parse("tel:" + phone_number));
if (ActivityCompat.checkSelfPermission(context, 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;
}
context.startActivity(callIntent1);
}
}
// in manifest add permission..
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Podobne pytania
Nowe pytania
android
Android to mobilny system operacyjny Google, używany do programowania lub tworzenia urządzeń cyfrowych (smartfony, tablety, samochody, telewizory, Wear, Glass, IoT). W przypadku tematów związanych z Androidem użyj tagów specyficznych dla Androida, takich jak android-intent, android-activity, android-adapter itp. W przypadku pytań innych niż programowanie lub programowanie, ale związanych ze strukturą Androida, użyj tego linku: https: // android.stackexchange.com.