Android的code,以验证自己的登录电子邮件 [英] Android code to verify my login e-mail

查看:205
本文介绍了Android的code,以验证自己的登录电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创造我已经通过发送一个验证code和验证用户的电子邮件地址的Andr​​oid应用程序重新指引用户在移动应​​用进入code

I'm trying to create an android application in which I've to verify the user's email address by sending a verification code and re-directing the user to enter the code in the mobile application.

在这种情况下,可以请你解释一下我如何保持用户已验证他的邮件ID的记录。我现在面临什么问题是,当我存储在共享preferences这些细节,当用户退出应用程序的细节将被删除。因此,系统将提示用户输入验证code多次

In this case, can you please explain how I can maintain a record that the user has verified his mail id. The problem what I'm facing is that when I store these details in Shared Preferences, the details get erased when the user exits the application. Therefore user is prompted to enter the verification code many times

此外,每当用户散发出来的我的应用程序,用户将被自动注销。我存储的共享preferences用户详细信息。因此,每当应用程序启动时,它要求一个登录。能否请您解释我如何让登录的,直到他自己选择只注销的用户的用户服务。

Also whenever the user comes out of the my application, the user is automatically logged out. I'm storing the user details in Shared Preferences. Therefore whenever the application is started it asks for a login. Can you please explain how I can make the user stay logged-in until the user he himself opts to log-out.

有没有什么办法可以实现这些细节,而无需使用SQLite数据库???

Is there any way I can achieve these details without using Sqlite database???

推荐答案

保存缓存文件的状态。为了那个原因


创建InternalStorage.java

Save the status in cache file. For that
Create InternalStorage.java

public final class InternalStorage{

        private InternalStorage() {}

        public static void writeObject(Context context, String key, Object object) throws IOException {
            FileOutputStream fos = context.openFileOutput(key, Context.MODE_PRIVATE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(object);
            oos.close();
            fos.close();
        }

        public static Object readObject(Context context, String key) throws IOException,
                ClassNotFoundException {
            FileInputStream fis = context.openFileInput(key);
            ObjectInputStream ois = new ObjectInputStream(fis);
            Object object = ois.readObject();
            return object;
        }
    }

现在核查用于第一时间之后,创建一个文件,在高速缓存状态

Now After the verification for the first time, create a file with status in cache

try {
    // Save the status like verified 
    InternalStorage.writeObject(this, "cache_fileName", "verified");

} catch (IOException e) {
    Log.e(TAG, e.getMessage());
} catch (ClassNotFoundException e){
    Log.e(TAG, e.getMessage());
}

和在MainActivity的onCreate方法,检查缓存文件的价值,如果文件中有值=验证,然后启动活动到你想要去的

And in the MainActivity's OnCreate Method, check for the cache file value, If the file has value = "verified", then start the activity to which you want to go

/*Check For status From Cache File*/
try {
    // Retrieve the file value
    verify= (String) InternalStorage.readObject(this, "cache_fileName");
} catch (IOException e) {
    Log.e("TAG", e.getMessage());
} catch (ClassNotFoundException e) {
    Log.e("TAG", e.getMessage());
}
try{
    if(verify.equals("verified")){
        startActivity("specify_your_activity");
    }
}catch (NullPointerException e){

}

在AndroidManifest文件

和将这个

And Put this in AndroidManifest file

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

这篇关于Android的code,以验证自己的登录电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆