Answer Found:
How to send email in background in Android ?
I'm working on an android app and one of the features requested is the ability to sign up for a news letter, which is simply sending a name and an email address. The client however does not have a server to host an application to receive this information and I would like to do it without sending it as an email. I'd like it just to say "You've successfully signed up for our newsletter" or something along those lines.
Is there anyway I can do this? If so, example code would be appreciated as my background is in C# and I'm working in Java.
Edit: Even sending a hidden e-mail without asking the client to login would be acceptable.
I think the notification method you might be looking for is Toasts. However, the validation of whether the customer has been registered will have to occur elsewhere.
Example:
Toast toast = Toast.makeText(getApplicationContext(), "You've successfully signed up for out newsletter", Toast.LENGTH_LONG);
toast.show();
It looks like you just want to display the message locally without server for demo purpose, right?
Well first of all, I don't really think you should learn Android in C# because of many reasons. First of all, you need Java to do Android development.
Here the simple scenario.
You have one activity called MainActivity where you have two text boxes called name and email.
You will now have a button called submit
Once user enters the name and email address and presses Submit button, it will take the user to a new activity called WelcomeActivity.
In android, you need an xml file that sets up the layout of your activity. I'll call this activity_email.xml.
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.maxphone.LoginActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Signup for email"
android:id="#+id/welcomeTextView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="40dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_below="#+id/welcomeTextView"
android:layout_marginTop="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Name"
android:id="#+id/usrnameTextView"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/userEditText"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Email Address"
android:id="#+id/emailTextView"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/emailEditText"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:focusableInTouchMode="true"
android:maxLines="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email_signed_up_smg"
android:id="#+id/loginErrorMsg"
android:layout_gravity="center_horizontal|end"
android:layout_marginTop="10dp"
android:layout_marginEnd="10dp"
android:singleLine="false"
android:textColor="#ffff0000"
android:visibility="invisible" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/signupConfirmBtn"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp" />
</LinearLayout>
</RelativeLayout>
Now in your MainActivity,
public class MainActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_login);
TextView txt = (TextView) findViewById(R.id.welcomeTextView);
txt.setTextSize(40);
final EditText usrname = (EditText) findViewById(R.id.userEditText);
final EditText email = (EditText) findViewById(R.id.emailEditText);
final TextView errorMsg = (TextView) findViewById(R.id.emailConfirmMsg);
final Button submitBtn = (Button) findViewById(R.id.emailConfirmBtn);
// Login Up button behavior
submitBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Staring MainActivity
Intent i = new Intent(getApplicationContext(), WelcomeActivity.class);
startActivity(i);
finish();
}
}
}
}
This class will display the Views (such as text views, edit texts, etc) and listen to user behavior. Once submitBtn is clicked, it will create an Intent (please do a research) and take the user to a new activity that intent defined.
and you can do similar work for WelcomeActivity to display welcome messages like Thank you for signing up! and such.
This is all locally done and does not need any kind of web activity. So this is basically for demo purpose.
Good luck!
I found the answer here, unfortunately it requires the hard coding of an e-mail and password which is highly insecure. I will have to make more considerations.
How to send email in background in Android ?
Related
I'm making a simple test app to wrap my head around reading text from TextViews in android.
My problem is: I have 2 TextViews, one for a username and one for a password field, and a button. The button calls a method that gets text from both TextViews. However, my username TextView is automatically selected when the app runs and I can type text into it, and I cannot deselect it and select the password field to write into, but I can click the button. Does anybody know what the issue might be?
Android 7.0 used for testing
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/userField"
android:layout_width="#dimen/textView_width"
android:layout_height="#dimen/textView_height"
android:layout_above="#id/passField"
android:layout_marginHorizontal="#dimen/activity_horizontal_margin"
android:layout_marginVertical="#dimen/activity_vertical_margin"
android:background="#color/LightCoral"
android:gravity="center_vertical"
android:hint="#string/user"
android:inputType="text"
android:textAlignment="gravity"
android:textSize="10pt"
android:visibility="visible" />
<TextView
android:id="#+id/passField"
android:layout_width="#dimen/textView_width"
android:layout_height="#dimen/textView_height"
android:layout_centerInParent="true"
android:layout_marginHorizontal="#dimen/activity_horizontal_margin"
android:layout_marginVertical="#dimen/activity_vertical_margin"
android:background="#color/LightCoral"
android:gravity="center_vertical"
android:hint="#string/pass"
android:inputType="textPassword"
android:textAlignment="gravity"
android:textSize="10pt"
android:visibility="visible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/passField"
android:layout_centerHorizontal="true"
android:width="#dimen/button_width"
android:height="#dimen/button_height"
android:background="#color/FireBrick"
android:onClick="uradi"
android:text="#string/button_tag"
android:textColor="#color/Black" />
</RelativeLayout>
EditText is better widget over TextView for handling user input. Replace your TextView with EditText
You should choose the controls that are suitable for the use of the sense.
The input of the username and password is generally used for EditText
I am trying to build a simple messaging app. which have one EditText and one Button at the bottom of the screen. when someone enters text and click the send button the entered text should appear as a msg on the top of the (EditText and Button). If the user have sent lots of msgs unable to fit to fit in the screen, the scrollbar for scrolling and viewing msgs should automatically appear.
I have made the layout as
<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"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send"
android:id="#+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#android:color/black"
android:onClick="sendMessage"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:hint="#string/edit_message"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/button"
android:layout_toStartOf="#+id/button"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
and Java code to fetch the msg is
public void sendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
}
I need someone to guide me how to proceed after this.
I want the msg to appear above each time. Any help or suggestion will be great helpful for me.
For a simpler solution, you might want to try using one textview. You just keep adding the new messages to it.
I would create my own custom layout just so that different combinations are possible (e.g timestamps, emojis). Basically a custom layout which draws all your different items on there.
You can use a custom listView with 9patch images.
I have 2 EditTexts on my screen. The first one works fine, but the second doesn't. I click on the first EditText and can enter text. But click on the second EditText and any input continues to appear in the first EditText.
Looking at other questions on the subject, there is talk of using setFocus and having onClick listeners for the EditText fields. Is this correct?
I have another app which had several screens with multiple EditTexts and never had to do this.
This is my current XML:
<TextView
android:id="#+id/namLabel"
android:layout_alignParentLeft="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name" />
<EditText
android:id="#+id/namTxt"
android:layout_below="#id/namLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:minWidth="200sp" />
<TextView
android:id="#+id/numLabel"
android:layout_alignParentLeft="true"
android:layout_below="#id/namTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="20sp"
android:paddingRight="10sp"
android:text="#string/units" />
<EditText
android:id="#+id/numTxt"
android:layout_toRightOf="#id/numLabel"
android:layout_alignBaseline="#id/numLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:inputType="numberDecimal"
android:minWidth="50sp" />
This is all the relevant code I have in the onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_game);
namText = (EditText) findViewById(R.id.namTxt);
numText = (EditText) findViewById(R.id.numTxt);
Please don't tell me I have to add a whole load of onClickListeners for these fields?
I found the problem. I just had to add the setFocusableInTouchMode to both EditText's:
android:focusableInTouchMode="true"
I didn't do that in my last app, so no idea why I have to now.
You don't need to add any listeners or setFocus. The only "strange" thing I see is that you are not wrapping your xml in a RelativeLayout. It should work just fine, just tested it.
Hi everyone I ve been searching this a lot but I couldn't find an answer that would work in my case. In my layout i have a listview and outside the list and more specific above i have an imageview an editText which work as a search and a custom Button!The problem is that when i press the button does not start the Activity which i have put in th Intent.Why is this happening?I cannot find the error and so far i had never problem with button events.
Here is my xml:
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView1"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="false"
android:layout_below="#+id/autoCompleteTextView1" >
</ListView>
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="LIST OF PATIENTS"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#33B5E5" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="90dp"
android:layout_height="85dp"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/textView1"
android:padding="2dp"
android:src="#drawable/search_user" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignBottom="#+id/autoCompleteTextView1"
android:layout_alignParentRight="true"
android:orientation="vertical" >
<Button
android:id="#+id/add"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_above="#+id/linearLayout1"
android:layout_alignParentRight="true"
android:background="#drawable/buttonadd"
android:onClick="button_click"
android:src="#drawable/add" />
</LinearLayout>
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_toLeftOf="#+id/linear"
android:ems="10"
android:hint="Search patient" />
the button is the right on the top next to autocomplete.In the .java doc i have right this code as far as concerned the button:
In the onCreate
addp=(Button) findViewById(R.id.add);
addp.setOnClickListener(this);
In th onClick
case R.id.add:
Intent add= new Intent(sqlviewpatients.this,afprognosis.class);
startActivity(add);
break;
I ve been doing the same thing to others button and they working only this one does not respond to onClick events.Please tell me what I am doing wrong?
thanks in advance
This is because your ids do not match:
addp=(Button) findViewById(R.id.add);
and:
<Button
android:id="#+id/addpatient"
Change the java to:
addp=(Button) findViewById(R.id.addpatient);
EDIT: If you are defining your onClick within the XML then you should not need to set an onClickListener within the java code. Just make the code:
Intent add= new Intent(sqlviewpatients.this,afprognosis.class);
startActivity(add);
within a method that is called button_click.
EDIT after Code update
Okay, after reading the code you just posted: sqlviewpatients:
what does customwindow3 look like? Does it inherit from ListActivity or what?
This class only implements onClickListener and so a bunch of code won't get executed, including onCreate unless of course, customwindow3 does
Original
1) your button's id is addpatient not add which is the clause if you switch statement
2) have you looked into doing this:
public void button_click(View v)
{
Intent .....
}
Also, from the snippet you posted this:
addp=(Button) findViewById(R.id.add);
addp.setOnClickListener(this);
shouldn't actually run (you'll get a null pointer exception) since there is no element with that id (unless of course you've defined that somewhere else and didn't show us).
First of all thanks everyone for your answers and your time!I appreciate it
Second i found where the error was. the onClick method should have an #overide above
I need my ratings bar to keep up with the user average rating. I have a main menu with several items which each have their own screen and description. I'm adding a rating bar to each screen so users can submit their product rating/see the average rating by others/see the number of ratings. Kind of like the customer reviews on the amazon app but without the bar graph. I have the xml file set up but need help with the java. Any help would be appreciated.
Here is an example of just one of the screens.
xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:text="TextView"
android:textSize="50dp" />
<TextView
android:id="#+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="TextView" />
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:layout_weight="50" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="150dp"
android:text="Submit" />
</LinearLayout>
java
public class MainActivity extends Activity {
RatingBar ratings;
TextView tv1, tv2;
Button b;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RatingBar rb = (RatingBar) findViewById(R.id.ratingbar);
}
}
In order to achieve something like that you will have to create an SQLiteDatabase on your app.
Store the ratingBar values for every product a user rates, inside your Database.
Post the values from your local SQLiteDatabase to a server.
Edit the values that you get in the server. Find max-min-middle etc. and store them on a "global" Database.
Post back to your Application the edited results.
Repeat the above steps on your own timeshift and you will have the desired result!