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

标签 android android-intent android-arrayadapter

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/

相关文章:

android - 使用变量时的 Gradle 库版本建议

java - Libgdx 对图像的操作应用于整个 Actor

android - 将信息从 CustomDialog 传递到主 Activity

android - BroadcastReceiver 未显示 onReceive 的任何日志

java - ArrayAdapter 中带有按钮的自定义 View

android - 如何将嵌套的 ArrayList 划分到 TabLayout 的每个布局

android - Python - MySQL 数据库更改后向 Android 应用程序发送通知

java - ANDROID:无法解析方法 getSupportActionBar()

java - 通过 Intent 打开whatsapp在Android 11中不起作用

java - 如何从自定义适配器动态设置 ListView 的 imageView 源?