1 回答
TA贡献2011条经验 获得超2个赞
这是一个例子
List<String> prods = new ArrayList<>();
List<String> quantity = new ArrayList<>();
smsSendToBtn.setOnClickListener(new View.OnClickListener() {
//private String Cart;
public void onClick(View view) {
DatabaseReference reff = FirebaseDatabase.getInstance().getReference("Cart List");
final DatabaseReference reff2= FirebaseDatabase.getInstance().getReference("Cart List");
reff.child("User View").child(Prevalent.CurrentOnlineUsers.getPhone()).child("Products").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snap: dataSnapshot.getChildren()){
String getDate = snap.getKey();
reff2.child("User View").child(Prevalent.CurrentOnlineUsers.getPhone()).child("Products").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snap1: dataSnapshot.getChildren()){
String myProductName = snap1.child("productName").getValue(String.class);
String myQuantity = snap1.child("quantity").getValue(String.class);
prods.Add(myProductName );
quantity.Add(myQuantity);
Toast.makeText(getApplicationContext(),myProductName + " " + myQuantity,Toast.LENGTH_SHORT).show();
}
setSMSData(prods,quantity);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
设置短信数据
private void setSMSData(List<String> products,List<String> quantitys) {
// add the phone number in the data
Uri uri = Uri.parse("smsto:" + "09257777547");
Intent smsSIntent = new Intent(Intent.ACTION_SENDTO, uri);
// add the message at the sms_body extra field
List<String> format = new ArrayList<>();
int i=-1;
foreach(String str in products){
i++;
format.Add(str+":"+quantitys[i];
}
String formats= Arrays.toString(format);
smsSIntent.putExtra("sms_body", "Order "+formats+" (Sent Via SKIP MOBILE)");
try{
startActivity(smsSIntent);
} catch (Exception ex) {
Toast.makeText(CartActivity.this, "Your sms has failed...",
Toast.LENGTH_LONG).show();
ex.printStackTrace();
}
}
添加回答
举报