如何发送一旦号码的用户preSS序列电子邮件序列、电子邮件、号码、用户

2023-09-04 07:27:54 作者:吹乱心事

我是新的android的世界。

I'm new in android world..

欲在我的应用程序发送,一旦用户的电子邮件输入一些数字序列。例如,如果用户输入* 1234等号码然后他presses一个按钮。后直接数目将使用的电子邮件地址被发送

I want in my application to send an email once the user enter some sequence of numbers.. For example, if the user enter "*1234" and other numbers then he presses a button. After that directly the number will be sent using an email address

推荐答案

不介意计算器的仇敌......这里是一个超级简单的方法来做到这一点...使用安卓的onClick 属性所有的按钮,使他们会每个看起来像这样在布局XML(使用不同的标签/文本除外):

Don't mind the haters on StackOverflow...here's a super simple way to do it...use the android:onClick attribute for all of your buttons so they'd each look something like this in the layout XML (except with different tag/text):

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="checkSequence"
    android:tag="0"
    android:text="0"/>

然后定义这个方法,并在你的的活动,这些领域

private final String FIRST_DIGIT = "*";
private final String SECOND_DIGIT = "1";
private final String THIRD_DIGIT = "2";
private final String FOURTH_DIGIT = "3";
private int counter = 0;

public void checkSequence(View button){

    String input = button.getTag().toString();

    switch (counter){
        case 0:
            if (input.equals(FIRST_DIGIT)){
                counter++;
            }
            break;
        case 1:
            if (input.equals(SECOND_DIGIT)){
                counter++;
            }else{
                //reset the counter b/c they've screwed up the sequence
                counter = 0;
            }
            break;
        case 2:
            if (input.equals(THIRD_DIGIT)){
                counter++;
            }else{
                counter = 0;
            }
            break;
        case 3:
            if (input.equals(FOURTH_DIGIT)){
                //here you know that they've finished the sequence, so send the email
                sendEmail();
                counter = 0;
            }
            break;
    }
}

然后搜索计算器/谷歌如何使用,以发送电子邮件的意图,你就可以写 sendEmail() 方法。

And then search StackOverflow/google for how to send an email using an Intent, and you'll be able to write the sendEmail() method.