Diese Methode funktioniert für eine bestimmte E-Mail, aber ich möchte, dass sie dynamisch ausgefüllt wird, wenn ein bestimmter Benutzer ausgewählt wird.Wie sende ich eine E-Mail an eine ausgewählte ID in Android App?
Irgendwelche Ideen ?? Dies ist mein Code für Details Aktivität
Ich habe eine Listenansicht, die auf Klick zeigt Details einer bestimmten Person, und ich habe eine Schaltfläche in dieser Details Aktivität, die nach dem Klicken sollte die bestimmte E-Mail-ID ausfüllen.
public class AgentDetails extends AppCompatActivity {
private TextView a_id;
private TextView a_fname;
private TextView a_lname;
private TextView a_phone;
private TextView a_email;
private TextView a_position;
private ImageButton sendEmail;
private Zeichenfolge JSON_STRING;
private String id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_agent_details);
Intent intent = getIntent();
id = intent.getStringExtra(Config.AGT_ID);
a_id = (TextView) findViewById(R.id.a_id);
a_fname = (TextView) findViewById(R.id.a_fname);
a_lname = (TextView) findViewById(R.id.a_lname);
a_phone = (TextView) findViewById(R.id.a_phone);
a_email = (TextView) findViewById(R.id.a_email);
a_position = (TextView) findViewById(R.id.a_position);
sendEmail = (ImageButton) findViewById(R.id.sendEmail);
a_id.setText(id);
a_fname.setText(intent.getStringExtra(Config.TAG_FNAME));
a_lname.setText(intent.getStringExtra(Config.TAG_LNAME));
a_phone.setText(intent.getStringExtra(Config.TAG_PHONE));
a_email.setText(intent.getStringExtra(Config.TAG_EMAIL));
a_position.setText(intent.getStringExtra(Config.TAG_POSITION));
getAgent();
}
public void process(View view)
{
Intent intent = null, chooser = null;
if(view.getId()== R.id.sendEmail)
{
intent = new Intent(intent.ACTION_SEND);
intent.setData(Uri.parse("mailto:"));
String[] to = {intent.setText(intent.getStringExtra(Config.TAG_EMAIL))};
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_SUBJECT, "Booking Request");
intent.putExtra(Intent.EXTRA_TEXT, "Need more information about booking");
intent.setType("message/rfc822");//need for MIME message type
chooser = Intent.createChooser(intent, "Send Email"); //selects the in-build email app
startActivity(chooser);
}
}
private void getAgent(){
class GetAgent extends AsyncTask<Void,Void,String>{
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(AgentDetails.this,"Fetching...","Wait...",false,false);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
showAgent(s);
}
@Override
protected String doInBackground(Void... params) {
RequestHandler rh = new RequestHandler();
String s = rh.sendGetRequestParam(Config.URL_GET_AGT,id);
return s;
}
}
GetAgent ga = new GetAgent();
ga.execute();
}
private void showAgent(String json){
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
JSONObject c = result.getJSONObject(0);
String fname = c.getString(Config.TAG_FNAME);
String lname = c.getString(Config.TAG_LNAME);
String phone = c.getString(Config.TAG_PHONE);
String email = c.getString(Config.TAG_EMAIL);
String position = c.getString(Config.TAG_POSITION);
a_fname.setText(fname);
a_lname.setText(lname);
a_phone.setText(phone);
a_email.setText(email);
a_position.setText(position);
} catch (JSONException e) {
e.printStackTrace();
}
}
/*@Override
public void onClick(View v) {
if(v == sendEmail)
{
}
}*/
}
Wo wird die Zeichenfolge aus für 'intent.getStringExtra' kommt? Sie setzen nie eine Zeichenfolge in die Absicht –
@ cricket_007 es kommt aus JSON-Array –
Umm, nein ist es nicht. Ein paar Zeilen davor hast du eine leere Absicht ... 'intent = new Intent();'. Bitte zeigen Sie eine [mcve] –