• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Need to use date from function in email intent.

carelv7

Newbie
Jul 4, 2017
18
1
Hi there. Hope you are well Really no idea how to go further, maybe even very basic, but just can't get it.
I manage to create get the datepicker going, and showing the selected date as a toast, but can't get the string thing going. The datepicer is a fragment.

Now I need to create a string of the date. So far I have a toast showing.

Code:
         public class MyDatePickerFragment extends DialogFragment {
  
       private String onDateSet;
    [USER=1021285]@override[/USER]
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);

        return new DatePickerDialog(getActivity(), dateSetListener, year, month, day);
    }

    private DatePickerDialog.OnDateSetListener dateSetListener =
            new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    Toast.makeText(getActivity(), "Delivery date is " + view.getYear() +
                            " / " + (view.getMonth() + 1) +
                            " / " + view.getDayOfMonth(), Toast.LENGTH_SHORT).show();

                }
            };

And use it in an email intent here. this is part of  adapter. 
                        
               case carel.twee.android.sasko.R.id.ic_email:
                         String extradata = "";
                         for(carel.twee.android.sasko.Model aModel : list) {
                         if (aModel.getNumberCases() > 0) {
                                     extradata += aModel.getBrand() + " \n" + aModel.getNumberCases() + " Units" + "\n";
                                        }}
                         Intent intent = new Intent(Intent.ACTION_SENDTO);
                         SharedPreferences sharedPreferences = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE);
                        String CustName = (sharedPreferences.getString(Name, " "));
                        String Num = (sharedPreferences.getString(CustNum, " "));
                        String CustRoute = (sharedPreferences.getString(Route, " "));
                        String CustPhone = (sharedPreferences.getString(Phone, " "));
                        //String DelDate = (MyDatePickerFragment.getString(dateView, " "));
                        intent.setData(Uri.parse("mailto:victor.grobbelaar@pioneerfoods.co.za"));
                       intent.putExtra(Intent.EXTRA_SUBJECT, "Order for: " + CustName);
                     intent.putExtra(Intent.EXTRA_TEXT, " Please order for: " + CustName+ "\n" + dateView   +"\nAccount Number: " + Num  + "\nRoute: " + CustRoute +"\n\nPlease call " + CustPhone + " if there is any uncertainty." +  "\n\n" + extradata);
                     if (intent.resolveActivity(getPackageManager()) != null) {
                      startActivity(intent);
                      }

Please be so kind and help.PS . Yes the code is sloppy, but I'm still learing.
 
Last edited by a moderator:
Thank you v. My apologies for only replying now. I got alright. I change the whole layout by placing the date picker in the same activity. But yes, I first had the date picker in a fragment, and had trouble (because I'm still new to Java) to pull it over to the other activity. Thanks again.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones