0

嗨,我开发了一个 android 应用程序.. 为此我正在创建一个登录页面......我已经创建了注册代码和登录选项现在我需要一个短信验证过程......在注册时用户的手机号码是收集并在注册时.. 一条短信从用户手机发送到提供的手机号码...并且短信必须是随机文本.. 用户需要在注册时输入此文本才能成功...有谁知道如何做到这一点请帮助...我正在提供我已经为登录页面开发的代码...。

主要活动

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;

public class MainActivity extends Activity {


     Button btnSignIn,btnSignUp;
    LoginDataBaseAdapter loginDataBaseAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        loginDataBaseAdapter=new LoginDataBaseAdapter(this);
        loginDataBaseAdapter=loginDataBaseAdapter.open();


        btnSignIn=(Button)findViewById(R.id.buttonSignIn);
        btnSignUp=(Button)findViewById(R.id.buttonSignUP);



        btnSignUp.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent intentSignUP=new Intent(getApplicationContext(),SignUPActivity.class);
                startActivity(intentSignUP);

            }
        });
    }

    public void signIn(View V)
    {
         final Dialog dialog = new Dialog(MainActivity.this);
         dialog.setContentView(R.layout.login);
         dialog.setTitle("Login");

         // get the References of views
         final  EditText editTextUserName=(EditText)dialog.findViewById(R.id.editTextUserNameToLogin);
         final  EditText editTextPassword=(EditText)dialog.findViewById(R.id.editTextPasswordToLogin);

         Button btnSignIn=(Button)dialog.findViewById(R.id.buttonSignIn);


         btnSignIn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                String userName=editTextUserName.getText().toString();
                String password=editTextPassword.getText().toString();

                // fetch the Password form database for respective user name
                String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);

                // check if the Stored password matches with  Password entered by user
                if(password.equals(storedPassword))
                {
                    Toast.makeText(MainActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
                    dialog.dismiss();
                }
                else
                {
                    Toast.makeText(MainActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
                }

            }
        });


         dialog.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // Close The Database
        loginDataBaseAdapter.close();
}
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation = "vertical"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/buttonSignIN"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Sign In"
        android:onClick="signIn" />

    <Button
        android:id="@+id/buttonSignUP"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/buttonSignIN"
        android:layout_alignParentLeft="true"
        android:text="Sign UP" />

</RelativeLayout>

注册.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:gravity="center_vertical" >


    <EditText
        android:id="@+id/editTextUserName"
        android:hint="User Name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editTextPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         android:hint="Password"
        android:inputType="textPassword" />

    <EditText
        android:id="@+id/editTextConfirmPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/buttonCreateAccount"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Create Account"
        android:layout_marginBottom="60dp" />


</LinearLayout>

登录.xml

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >


        <EditText
            android:id="@+id/editTextUserNameToLogin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="User Name"
            android:ems="10" >
            <requestFocus />
        </EditText>

        <EditText
            android:id="@+id/editTextPasswordToLogin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPassword"
            android:hint="Password" />

        <Button
            android:id="@+id/buttonSignIn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Sign In" />


    </LinearLayout>
4

1 回答 1

1

You can use a web service and send the Mobile to web service during signup,

Then use an algorithm to generate a unique code based on the mobile number and send this code as an SMS to the user

Use the same algorithm in your android app to generate the unique code which is dependent on mobile number

Every mobile number will have only one unique code !!

so these two will match and the user could sign in.

Learn to write a web service and consume it in your app

http://www.c-sharpcorner.com/uploadfile/88b6e5/how-to-call-web-service-in-android-using-soap/

http://www.codeproject.com/Articles/304302/Calling-Asp-Net-Webservice-ASMX-From-an-Android-Ap

http://programmertoolbox.wordpress.com/2013/04/07/communicate-between-asp-net-webservice-and-android-app/

http://www.codeproject.com/Articles/29305/Consuming-NET-Web-Services-via-the-kSOAP-library

Code eg.

                    import org.ksoap2.*;
                    import org.ksoap2.serialization.SoapObject;
                    import org.ksoap2.serialization.SoapPrimitive;
                    import org.ksoap2.serialization.SoapSerializationEnvelope;
                    import org.ksoap2.transport.*;

                    public class soapclass 
                    {
                    private String[] resultValue;
                    private String res;
                    final String NAMESPACE = "http://tempuri.org/"; //the namespace that you'll find in the header of your asmx webservice
                    String METHOD_NAME= "HelloWorld"; //the webservice method that you want to call
                    String SOAP_ACTION = NAMESPACE+METHOD_NAME;
                    final String URL = "http://192.168.1.3/Myapp/WebService1.asmx"; //the url of your webservice
                    public soapclass()
                    {

                    this.SOAP_ACTION =NAMESPACE+METHOD_NAME;
                    }
                    public String callHello()
                    {
                    try {

                    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                    envelope.dotNet = true;
                    envelope.setOutputSoapObject(request);
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                    androidHttpTransport.call(SOAP_ACTION, envelope);
                    SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); //get the response from your webservice
                    res= response.toString();

                    }
                    catch (Exception e) {

                    res =e.getMessage();
                    }
                    return res;
                    }
于 2013-09-11T06:31:17.127 回答