2015-09-14 102 views
0

答发现: How to send email in background in Android ?从Android发送数据没有电子邮件或服务器?

我工作的一个Android应用程序及所要求的功能之一是注册一个新闻信,这是简单的发送姓名和电子邮件地址的功能。然而,客户端没有服务器来托管应用程序来接收这些信息,我想这样做而不用将它作为电子邮件发送。我只想说“你已经成功注册了我们的通讯”或其他内容。

有反正我可以做到这一点吗?如果是这样,示例代码将赞赏,因为我的背景是在C#中,我正在使用Java。

编辑:即使发送一个隐藏的电子邮件,而不要求客户端登录将是可以接受的。

+0

这有点含糊。您正试图让通知反弹回应用程序以验证它们已被注册?如果没有服务器,它应该从哪里反弹回来? – nukeforum

+0

是的,我知道没有服务器联系。这就是为什么我问我是否可以在没有人的情况下做到这一点。即使发送电子邮件而不要求用户登录也是可以接受的。 – Eidenai

+0

如果没有联系服务器,该人如何注册任何内容? – nukeforum

回答

0

我认为您可能正在寻找的通知方法是Toasts。但是,验证客户是否已注册将不得不在别处发生。

例子:

Toast toast = Toast.makeText(getApplicationContext(), "You've successfully signed up for out newsletter", Toast.LENGTH_LONG); 
toast.show(); 
0

看起来你只是想不服务器演示目的本地显示的消息,对不对?

首先,我并不认为你应该在C#中学习Android,原因很多。首先,你需要Java来做Android开发。

这里简单的场景。

您有一项活动叫做MainActivity,其中有两个文本框叫做nameemail

现在,您将有一个按钮叫submit

一旦用户输入姓名和电子邮件地址,并按下提交按钮,将用户带到一个新的活动叫做WelcomeActivity

在android中,您需要一个xml文件来设置您的活动布局。我会打电话给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> 

现在,在您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(); 
     } 
    } 
} 
} 

这个类将显示Views(如文本视图,编辑文本等),并听取用户的行为。一旦submitBtn被点击,它将创建一个意图(请做一个研究),并将用户带到意图定义的新活动。

你可以做类似的工作WelcomeActivity显示欢迎消息,如感谢您注册!等等。

这是在本地完成的,不需要任何种类的网络活动。所以这基本上是为了演示的目的。

祝你好运!

+1

他提到他的问题是他是C#程序员,而不是他正在使用C#编写Android代码。 – nukeforum

+0

好的,我可能理解错了。但这个答案仍然会回答他的问题:) –

相关问题