为什么凌空没有完全读完我的网址字符串

时间:2018-07-19 18:58:45

标签: android-volley

我已经足够长时间调用此API。但是现在,除了我在适配器中放置了sendmsgnow()函数之外,volley无法使用与以前相同的代码完全读取URL字符串。当我将URL放入浏览器时,它就可以正常工作。 附言:-我已更改了密码,因为它是一个付费短信网关。

错误:

errorpic1

errorpic2

//Adapter.java

public class Adapter extends RecyclerView.Adapter<Adapter.Viewholder> {
String contactdonor;
private static final String URL = "http://Lifetimesms.com/plain?username=opvg&password=mypassword&to=03365297078&from=ComapnyName&message=uyy kugtyf rtd ydrtjyty tku.";
private ArrayList<UserInformation> list;
private Context ctx;
public Adapter(ArrayList<UserInformation> list, Context ctx) {
    this.list = list;
    this.ctx = ctx;
}

@Override
public Viewholder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_layout, parent, false);
    Viewholder myHolder = new Viewholder(view);
    return myHolder;
}

@Override
public void onBindViewHolder(Viewholder holder, int position) {
    final UserInformation val = list.get(position);
    holder.edt_contact_no.setText(val.getContact_no());
    holder.edt_blood_group.setText(val.getBlood_group());
    holder.btn_approve.setText("approve");
    holder.btn_decline.setText("decline");
    holder.btn_approve.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(ctx, "bloodgrp got= " + val.getBlood_group(), Toast.LENGTH_SHORT).show();
            sendmsg(val);
        }
    });

    holder.btn_decline.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //code to delete data
            FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
            DatabaseReference reference = firebaseDatabase.getReference("Patients");
            reference.child(val.getContact_no()).removeValue();
        }
    });
}

public void sendmsg(final UserInformation val) {
    //Toast.makeText(ctx, "sendmsg called", Toast.LENGTH_SHORT).show();
    //Toast.makeText(ctx, "blood group received" + val.getBlood_group(), Toast.LENGTH_SHORT).show();
    FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
    DatabaseReference reference = firebaseDatabase.getReference("Donors");
    Query query = reference.orderByChild("blood_group_donor").equalTo(val.getBlood_group());
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            DonorInformation donor = null;
            for (DataSnapshot data : dataSnapshot.getChildren()) {
                donor = data.getValue(DonorInformation.class);
                contactdonor = donor.getContact_no_donor();
                Toast.makeText(ctx, "contactno is " + contactdonor, Toast.LENGTH_SHORT).show();
                nowsendtxt();
            }
            // Toast.makeText(ctx, "contactno selected 0is=  " + contact, Toast.LENGTH_SHORT).show();
        }

        private void nowsendtxt() {
            //Toast.makeText(ctx, "contactno received" + contactdonor, Toast.LENGTH_SHORT).show();
            StringRequest request = new StringRequest(URL, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(ctx, "successful", Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(ctx, "error", Toast.LENGTH_SHORT).show();
                }
            }//
            );
            RequestQueue requestQueue = Volley.newRequestQueue(ctx);
            requestQueue.add(request);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
   /*public void nowsendtxt(String contactdonor,UserInformation p )
    {
        Toast.makeText(ctx, "contactno received" + contactdonor, Toast.LENGTH_SHORT).show();
        UserInformation patient=p;
        String patient_name,bloodgrp_common;
        patient_name=patient.getPatient_name();
         bloodgrp_common=patient.getBlood_group();
        StringRequest request = new StringRequest(URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Toast.makeText(ctx, "successful", Toast.LENGTH_SHORT).show();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(ctx, "error", Toast.LENGTH_SHORT).show();

            }
        }
        );
        RequestQueue requestQueue = Volley.newRequestQueue(ctx);
        requestQueue.add(request);

    }*/

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

    public static class Viewholder extends RecyclerView.ViewHolder {
        EditText edt_blood_group;
        EditText edt_contact_no;
        Button btn_approve, btn_decline;

        public Viewholder(View itemView) {
            super(itemView);
            edt_blood_group = (EditText) itemView.findViewById(R.id.edt_blood_group);
            edt_contact_no = (EditText) itemView.findViewById(R.id.edt_contact_no);
            btn_approve = (Button) itemView.findViewById(R.id.btn_approve);
            btn_decline = (Button) itemView.findViewById(R.id.btn_decline);
        }
    }
}

0 个答案:

没有答案