我正在创建的应用程序中有一个部分允许用户将信息输入到八个不同的TextField中。那些字段是:
现在,当这些信息完成并且用户点击提交按钮时,我要么想要在点击按钮之后直接将信息发送到我的个人电子邮件地址,要么存储要在稍后查看的信息。我对Android开发比较陌生,但是,我认为我应该在按下按钮时调用的方法中执行以下操作:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.jquery.min.js"></script>
<script src="https://rawgit.com/leocaseiro/angular-chosen/master/dist/angular-chosen.min.js">
</script>
<link data-require="chosen@*" data-semver="1.0.0" rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.min.css" />
<div ng-app="myApp" ng-controller="MainCtrl">
<select chosen multiple ng-model="state" ng-options="s.id as s.title for s in states">
<option value=""></option>
</select>
</div>
我搜索并搜索过,找不到任何我想要完成的事情。有可能将信息直接发送到我的电子邮件吗?或者我是否需要以某种方式存储它以供以后查看。到目前为止我的Java文件:
final EditText moverName = (EditText)findViewById(R.id.nameRegistration);
String name = regName.getText().toString();
提前致谢!
答案 0 :(得分:2)
在您的情况下,您有两个发送电子邮件的选项:
使用应用程序发送电子邮件:在这种情况下,您只能启动电子邮件应用程序,其中包含您要在电子邮件正文中预先填充的所有信息。但是,在这种情况下,你必须再次按下最后的“发送”。您可以在此处查看详细信息 - How to open Email program via Intents (but only an Email program)
与MailChimp,sendgrid等任何电子邮件提供商集成,并直接通过您的应用或后端进行API调用。
答案 1 :(得分:1)
我已经用这个解决方案复制了你的问题,它没有经过测试,但我相信它会为你指明一个好的方向。
要在您的应用中保存,您可以执行此操作
布局文件
public class ConsumptionActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, OnChartValueSelectedListener, OnSeekBarChangeListener {
protected BarChart mChart;
private SeekBar mSeekBarX, mSeekBarY;
private TextView tvX, tvY;
private Typeface mTf;
protected String[] mDays = new String[] {
"Day 1","Day 2","Day 3","Day 4","Day 5","Day 6","Day 7","Day 8","Day 9","Day 10","Day 11","Day 12","Day 13","Day 14","Day 15",
"Day 16","Day 17","Day 18","Day 19","Day 20","Day 21","Day 22","Day 23","Day 24","Day 25","Day 26","Day 27","Day 28","Day 29","Day 30"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_consumption);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Intent intent = getIntent();
LoginAuthentification loggedIn = (LoginAuthentification) intent.getExtras().getSerializable("LoginClass");
Spinner spinner = (Spinner) findViewById(R.id.accountDropdown);
SpinnerAdapter snprAdapter = new ArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item, loggedIn.getAccountList());
spinner.setAdapter(snprAdapter);
// Create an ArrayAdapter using the string array and a default spinner layout
/*ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.test, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);*/
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// An item was selected. You can retrieve the selected item using
// parent.getItemAtPosition(pos)
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
});
ObjectMapper mapper = new ObjectMapper();
APICalls accountInfo = new APICalls();
AccountDetails accountInUse = new AccountDetails();
try {
accountInUse = mapper.readValue(String.valueOf(accountInfo.AccountDetails(loggedIn.getToken(),loggedIn.getAccountList().get(0))), AccountDetails.class);
} catch (Exception e) {
e.printStackTrace();
}
/*tvX = (TextView) findViewById(R.id.tvXMax);
tvY = (TextView) findViewById(R.id.tvYMax);
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);*/
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setDescription("Water Consumption Details");
mChart.animateXY(8000, 8000);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(true);
// mChart.setDrawYLabels(false);
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(mTf);
xAxis.setDrawGridLines(false);
xAxis.setSpaceBetweenLabels(2);
YAxisValueFormatter custom = new MyYAxisValueFormatter();
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTf);
leftAxis.setLabelCount(8, false);
leftAxis.setValueFormatter(custom);
leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(mTf);
rightAxis.setLabelCount(8, false);
rightAxis.setValueFormatter(custom);
rightAxis.setSpaceTop(15f);
rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
l.setForm(Legend.LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
//l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
//"def", "ghj", "ikl", "mno" });
//l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
//"def", "ghj", "ikl", "mno" });
setData(30, 50);
// setting data
/* mSeekBarY.setProgress(50);
mSeekBarX.setProgress(12);
mSeekBarY.setOnSeekBarChangeListener(this);
mSeekBarX.setOnSeekBarChangeListener(this);*/
// mChart.setDrawLegend(false);
/*
APICalls callsForAll = new APICalls();
try {
callsForAll.AccountDetails(token.get(0),token.get(1));
} catch (Exception e) {
e.printStackTrace();
}
final TextView nameView = (TextView) findViewById(R.id.name);
*/
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.consumption, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_Alerts) {
} else if (id == R.id.nav_settings) {
}
else if (id == R.id.nav_Logout){
// LOGOUT LOGIC SHOULD GO HERE
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
private void setData(int count, float range) {
ArrayList<String> xVals = new ArrayList<String>();
for (int i = 0; i < count; i++) {
xVals.add(mDays[i]);
}
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
for (int i = 0; i < count; i++) {
float mult = (range + 1);
float val = (float) (Math.random() * mult);
yVals1.add(new BarEntry(val, i));
}
BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
set1.setBarSpacePercent(35f);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
set1.setColors(new int[]{R.color.neptuneOrange,R.color.colorPrimary});
BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(mTf);
mChart.setData(data);
}
@SuppressLint("NewApi")
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
if (e == null)
return;
RectF bounds = mChart.getBarBounds((BarEntry) e);
PointF position = mChart.getPosition(e, AxisDependency.LEFT);
Log.i("bounds", bounds.toString());
Log.i("position", position.toString());
Log.i("x-index",
"low: " + mChart.getLowestVisibleXIndex() + ", high: "
+ mChart.getHighestVisibleXIndex());
}
public void onNothingSelected() {
};
}
活动页面
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.inducesmile.emailapplication.MainActivity">
<EditText
android:id="@+id/nameRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter name"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userStreetAddressRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Address"
android:layout_below="@+id/nameRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userCityRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter City"
android:layout_below="@+id/userStreetAddressRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userStateRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter State"
android:layout_below="@+id/userCityRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userZipRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Zip Code"
android:layout_below="@+id/userStateRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userPhoneRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:layout_below="@+id/userZipRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userEmailRegistration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email"
android:layout_below="@+id/userPhoneRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/userDOB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter DOB"
android:layout_below="@+id/userEmailRegistration"
android:layout_marginTop="8dp"
android:layout_centerHorizontal="true"/>
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:padding="20dp"
android:layout_marginTop="16dp"
android:layout_below="@+id/userDOB"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
要将信息发送到您的电子邮件,您可以使用
Android Intent
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.HashSet;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
private EditText userName;
private EditText userStreetAddress;
private EditText userCity;
private EditText userState;
private EditText userZip;
private EditText userPhone;
private EditText userEmail;
private EditText userDOB;
private SharedPreferences prefs;
private boolean hasDataBeenSaved;
private Set<String> set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prefs=this.getSharedPreferences("settings", Context.MODE_PRIVATE);
set = prefs.getStringSet("Personal Information", null);
if(set.size() > 0){
hasDataBeenSaved = true;
}
if(hasDataBeenSaved){
// display the store personal information
}
userName = (EditText)findViewById(R.id.nameRegistration);
userStreetAddress = (EditText)findViewById(R.id.userStreetAddressRegistration);
userCity = (EditText)findViewById(R.id.userCityRegistration);
userState = (EditText)findViewById(R.id.userStateRegistration);
userZip = (EditText)findViewById(R.id.userZipRegistration);
userPhone = (EditText)findViewById(R.id.userPhoneRegistration);
userEmail = (EditText)findViewById(R.id.userEmailRegistration);
userDOB = (EditText)findViewById(R.id.userDOB);
Button submitButton = (Button)findViewById(R.id.submit_button);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!hasDataBeenSaved){
// Data has not been save then save them
String name = userName.getText().toString();
String address = userStreetAddress.getText().toString();
String city = userCity.getText().toString();
String state = userState.getText().toString();
String zip = userZip.getText().toString();
String phone = userPhone.getText().toString();
String email = userEmail.getText().toString();
String dob = userDOB.getText().toString();
if(!isEmpty(name) || !isEmpty(address) || !isEmpty(city) || !isEmpty(state) || !isEmpty(zip) || !isEmpty(phone) || !isEmpty(email) || !isEmpty(dob)){
Toast.makeText(MainActivity.this, "All input field must be filled", Toast.LENGTH_LONG).show();
return;
}
Set<String> set = new HashSet<String>();
set.add(name);
set.add(address);
set.add(city);
set.add(state);
set.add(zip);
set.add(phone);
set.add(email);
set.add(dob);
SharedPreferences.Editor edit = prefs.edit();
edit.putStringSet("Personal Information", set);
edit.commit();
}
}
});
}
private boolean isEmpty(String input){
if(input.equals("")){
return true;
}
return false;
}
}
在这种情况下,它只会启动客户端电子邮件应用程序