gpt4 book ai didi

android - 如何使数组适配器中的 Intent.ACTION_CALL android 面向 Activity 未找到异常

转载 作者:行者123 更新时间:2023-11-29 15:57:00 25 4
gpt4 key购买 nike

i am using array adapter to load the data in listview. in list view i have phone number , if the user clicks the number , calling function should hapen.

My array adapter class as follows

public class PendingDeliveryAdapter extends ArrayAdapter<PendingDeliveryPojoClass>{

private LayoutInflater inflater;
private Context context;
public PendingDeliveryAdapter(Context context,List<PendingDeliveryPojoClass> data)
{
super(context,R.layout.listview_pending_delivery,data);
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

And get view method so on...

code to call the calling functions in button click

@Override
public void onClick(View view) {
Intent phoneIntent = new Intent(Intent.ACTION_CALL);
phoneIntent.setData(Uri.parse(holder.delivery_phone_number.getText().toString()));
try {
context.startActivity(phoneIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getContext(),
"Call faild, please try again later.", Toast.LENGTH_SHORT).show();
}
}

i am facing activity not found exception . how to solve this?

最佳答案

Intent.ACTION_CALL的正确使用是

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

因此 tel: 在您正在设置的 Intent 数据中缺失。为了让你的代码工作,改变

phoneIntent.setData(Uri.parse(holder.delivery_phone_number.getText().toString()));

phoneIntent.setData(Uri.parse("tel:" + holder.delivery_phone_number.getText().toString()));

关于android - 如何使数组适配器中的 Intent.ACTION_CALL android 面向 Activity 未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com