如何处理HWAI保护:从应用上下文错误调用错误?

时间:2019-05-09 16:44:35

标签: android

我正在尝试通过单击按钮打开拨号盘,并在回收者视图中显示当前人员的电话号码,但出现上述错误。每当拨号盘打开时,它都会使用与传递的号码不同的号码打开。

调用ACTION-DIAL的适配器文件

<include layout="@layout/data_layout"/>     
<include layout="@layout/button_layout"
     android:layout_alignBottom="@layout/data_layout"
     android:layout_height="240dp" (Use @dimen as best practise)
     android:layout_width="wrap_content" />

logcat

public class BloodRequestAdapter extends RecyclerView.Adapter<BloodRequestAdapter.MyViewHolder> {

    Context context;
    ArrayList<BloodRequestList> bloodRequestList;
    String requesterNumber;

    public BloodRequestAdapter(Context c, ArrayList<BloodRequestList> b) {
        context = c;
        bloodRequestList = b;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.user, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
        Collections.reverse(bloodRequestList);
        myViewHolder.name.setText(bloodRequestList.get(i).getPatientName());
        myViewHolder.bloodgroup.setText(bloodRequestList.get(i).getBloodGroup());
        myViewHolder.quantity.setText(bloodRequestList.get(i).getQuantity());
        myViewHolder.hospitalname.setText(bloodRequestList.get(i).getHospitalName());
        myViewHolder.hospitaladdress.setText(bloodRequestList.get(i).getHospitalAddress());
        myViewHolder.textViewDate.setText(bloodRequestList.get(i).getDate());
        requesterNumber=bloodRequestList.get(i).getPhone();
        myViewHolder.dial.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel:" +requesterNumber));
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return bloodRequestList.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        TextView name, bloodgroup, quantity,hospitalname, hospitaladdress, textViewDate;
        Button dial;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.textViewUserName);
            bloodgroup = itemView.findViewById(R.id.textViewUserBloodGroup);
            quantity = itemView.findViewById(R.id.textViewUserQuantity);
            hospitalname = itemView.findViewById(R.id.textViewUserHospitalName);
            hospitaladdress = itemView.findViewById(R.id.textViewUserHospitalAddressFeed);
            textViewDate = itemView.findViewById(R.id.textViewUserDate);
            dial=itemView.findViewById(R.id.buttonDial);
        }
    }

}

0 个答案:

没有答案