安卓基于WifiScanner的签到APP
没图说个JB?首先上图:
友情提醒:后台数据库使用的是Bmob后端云
主要设计思路:首先选一个附近的wifi,输入签到码,进行签到。
签到之后会启动一个后台线程每隔一段时间扫描附近wifi,检测扫描范围内,是否存在之前签到时选择的wifi。
若不存在,那么就会往数据库塞一条中途离场信息。
这是工程的主要目录,包。
嗯对的,首先是AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.b140414.njupt.checkins"> <!-- 允许联网 --> <uses-permission android:name="android.permission.INTERNET" /> <!-- 获取GSM(2g)、WCDMA(联通3g)等网络状态的信息 --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 获取wifi网络状态的信息 --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 保持CPU 运转,屏幕和键盘灯有可能是关闭的,用于文件上传和下载 --> <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- 获取sd卡写的权限,用于文件上传和下载 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 允许读取手机状态 用于创建BmobInstallation --> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/> <application android:allowBackup="true" android:icon="@drawable/logo" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".LoginActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" /> <activity android:name=".Register" /> <service android:name="service.WifiCheck_ch" /> <activity android:name=".ScanActivity"></activity> </application> </manifest>
登录界面:
activity_login.XML:
<?xml version="1.0" encoding="utf-8"?> <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.b140414.njupt.checkins.LoginActivity" android:background="@drawable/background"> <Button android:layout_width="150dp" android:layout_height="wrap_content" android:text="登录" android:id="@+id/button_login" android:textSize="20dp" android:onClick="login_btn" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:background="#00000000" android:layout_above="@+id/button" android:layout_centerHorizontal="true" /> <Button android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/button_re" android:textSize="15dp" android:background="@android:drawable/ic_menu_edit" android:onClick="register_btn" android:layout_alignTop="@+id/button" android:layout_alignParentStart="true" /> <ImageView android:layout_width="100dp" android:layout_height="100dp" android:id="@+id/imageView" android:src="@drawable/logo" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> <RelativeLayout android:layout_width="200dp" android:layout_height="100dp" android:id="@+id/relativeLayout" android:layout_marginTop="62dp" android:layout_below="@+id/imageView" android:layout_centerHorizontal="true"> <EditText android:layout_width="120dp" android:layout_height="30dp" android:id="@+id/account_et" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:textSize="15dp" android:background="@drawable/abc_textfield_search_material" android:phoneNumber="true" android:layout_alignParentTop="true" android:layout_toEndOf="@+id/imageView2" /> <EditText android:layout_width="120dp" android:layout_height="30dp" android:id="@+id/password_et" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:textSize="15dp" android:background="@drawable/abc_textfield_search_material" android:password="true" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:layout_marginRight="30dp" /> <ImageView android:layout_width="20dp" android:layout_height="20dp" android:id="@+id/imageView2" android:background="@drawable/user" android:layout_marginRight="5dp" android:layout_alignBottom="@+id/account_et" android:layout_alignStart="@+id/imageView4" /> <ImageView android:layout_width="20dp" android:layout_height="20dp" android:id="@+id/imageView4" android:layout_alignBottom="@+id/password_et" android:layout_toStartOf="@+id/password_et" android:layout_marginRight="5dp" android:background="@drawable/lock" /> </RelativeLayout> <Button android:layout_width="30dp" android:layout_height="30dp" android:id="@+id/button" android:background="@android:drawable/ic_delete" android:textSize="15dp" android:onClick="quit_login_btn" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_above="@+id/textView" android:layout_alignParentEnd="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="注册" android:id="@+id/textView" android:layout_alignParentBottom="true" android:layout_alignParentStart="true" android:textColor="@color/abc_primary_text_disable_only_material_dark" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="退出" android:id="@+id/textView4" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" android:textColor="@color/abc_primary_text_disable_only_material_dark" /> <ImageView android:layout_width="100dp" android:layout_height="30dp" android:id="@+id/imageView6" android:layout_below="@+id/imageView" android:layout_centerHorizontal="true" android:src="@drawable/qiandao" /> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RadioGroup_type" android:orientation="horizontal" android:layout_below="@+id/relativeLayout" android:layout_centerHorizontal="true" android:layout_marginTop="38dp"> <RadioButton android:layout_width="60dp" android:layout_height="wrap_content" android:text="学生" android:id="@+id/radioButton_s" android:checked="true" android:layout_marginTop="0dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" /> <RadioButton android:layout_width="60dp" android:layout_height="wrap_content" android:text="老师" android:id="@+id/radioButton_t" android:checked="false" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginTop="0dp" /> </RadioGroup> </RelativeLayout>
LoginActivity:
package com.b140414.njupt.checkins; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Toast; import bmob_table.User; import java.util.List; import cn.bmob.v3.Bmob; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.listener.FindListener; public class LoginActivity extends AppCompatActivity { private EditText account_et; private EditText password_et; private RadioGroup radioGroup; private RadioButton radioButton_s,radioButton_t; private String userType = "s"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); Bmob.initialize(this, "502aa80df90be300b2af61b48838cc90"); account_et=(EditText)findViewById(R.id.account_et); password_et=(EditText)findViewById(R.id.password_et); radioGroup = (RadioGroup)findViewById(R.id.RadioGroup_type); radioButton_s = (RadioButton)findViewById(R.id.radioButton_s); radioButton_t = (RadioButton)findViewById(R.id.radioButton_t); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId == radioButton_t.getId()){ userType = "t"; } else { if (checkedId == radioButton_s.getId()) { userType = "s"; } else { } } } }); } //登录按钮响应事件 public void login_btn(View view){ final String account=account_et.getText().toString(); final String password=password_et.getText().toString(); if(account.equals("")){ Toast.makeText(LoginActivity.this, "请输入您的手机号!", Toast.LENGTH_LONG).show(); } else if(password.equals("")){ Toast.makeText(LoginActivity.this,"请输入您的密码!",Toast.LENGTH_LONG).show(); }else { BmobQuery<User> query=new BmobQuery<>(); query.addWhereEqualTo("account",account); query.findObjects(LoginActivity.this,new FindListener<User>() { @Override public void onSuccess(List<User> users) { if(users.size()==0){ Toast.makeText(LoginActivity.this,"账户不存在!",Toast.LENGTH_LONG).show(); return; } for(User a:users){ if(!a.getPassword().equals(password)) { Toast.makeText(LoginActivity.this, "账户或密码有误,请重新输入!", Toast.LENGTH_LONG).show(); return; } else{ if(userType.equals("t")) { Intent intent = new Intent(); intent.setClass(LoginActivity.this, MainActivity.class); intent.putExtra("account", account); intent.putExtra("realName", a.getRealName()); startActivity(intent); } else { if(userType.equals("s")){ Intent intent = new Intent(); intent.setClass(LoginActivity.this, ScanActivity.class); intent.putExtra("account", account); intent.putExtra("realName", a.getRealName()); startActivity(intent); } else { Toast.makeText(LoginActivity.this, "请选择正确的用户类型", Toast.LENGTH_LONG).show(); } } } } } @Override public void onError(int i, String s) { Toast.makeText(LoginActivity.this,"登录失败",Toast.LENGTH_LONG).show(); } }); } } //注册按钮响应事件 public void register_btn(View view) { Intent intent=new Intent(); intent.setClass(LoginActivity.this,Register.class); startActivity(intent); } //退出按钮响应事件 public void quit_login_btn(View view) { finish(); } }
注册界面:
activity_register.XML:
<?xml version="1.0" encoding="utf-8"?> <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.b140414.njupt.checkins.Register" android:background="@drawable/background"> <ImageView android:layout_width="100dp" android:layout_height="70dp" android:id="@+id/imageView3" android:src="@drawable/logo" android:layout_alignParentTop="true" android:layout_toStartOf="@+id/imageView7" /> <Button android:layout_width="200dp" android:layout_height="60dp" android:text="注册" android:id="@+id/button_queding" android:background="@drawable/abc_ab_share_pack_mtrl_alpha" android:textSize="20dp" android:onClick="register_sure" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_below="@+id/relativeLayout2" android:layout_marginTop="20dp" android:layout_alignEnd="@+id/relativeLayout2" android:layout_alignStart="@+id/relativeLayout2" /> <Button android:layout_width="40dp" android:layout_height="40dp" android:id="@+id/button_tuichu" android:background="@android:drawable/ic_menu_revert" android:textSize="20dp" android:onClick="register_quit_btn" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_above="@+id/textView_back" android:layout_alignParentEnd="true" /> <RelativeLayout android:layout_width="wrap_content" android:layout_height="150dp" android:id="@+id/relativeLayout2" android:layout_marginTop="63dp" android:layout_below="@+id/imageView3" android:layout_centerHorizontal="true"> <EditText android:layout_width="150dp" android:layout_height="25dp" android:id="@+id/register_account_et" android:background="@drawable/abc_textfield_search_material" android:phoneNumber="true" android:layout_marginLeft="10dp" android:layout_alignParentTop="true" android:layout_toEndOf="@+id/textView3" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:textSize="15dp" /> <EditText android:layout_width="150dp" android:layout_height="25dp" android:id="@+id/register_password_et" android:background="@drawable/abc_textfield_search_material" android:password="true" android:layout_marginLeft="0dp" android:layout_below="@+id/register_account_et" android:layout_alignStart="@+id/register_account_et" android:layout_marginTop="10dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:textSize="15dp" /> <EditText android:layout_width="150dp" android:layout_height="25dp" android:id="@+id/password_again_et" android:background="@drawable/abc_textfield_search_material" android:password="true" android:layout_marginLeft="0dp" android:layout_below="@+id/register_password_et" android:layout_alignStart="@+id/register_password_et" android:layout_marginTop="10dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:textSize="15dp" /> <EditText android:layout_width="150dp" android:layout_height="25dp" android:id="@+id/realName_et" android:background="@drawable/abc_textfield_search_material" android:layout_marginLeft="0dp" android:layout_below="@+id/password_again_et" android:layout_alignStart="@+id/password_again_et" android:layout_marginTop="10dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:textSize="15dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="再输密码:" android:id="@+id/textView3" android:textSize="15dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginLeft="0dp" android:layout_above="@+id/realName_et" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名:" android:id="@+id/textView_x" android:textSize="15dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginLeft="0dp" android:layout_alignBottom="@+id/realName_et" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码:" android:id="@+id/textView_m" android:textSize="15dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginLeft="0dp" android:layout_alignBottom="@+id/register_password_et" android:layout_alignParentStart="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="手机号:" android:id="@+id/textView_z" android:textSize="15dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginLeft="0dp" android:layout_marginRight="5dp" android:layout_above="@+id/register_password_et" android:layout_alignParentStart="true" /> </RelativeLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="返回" android:id="@+id/textView_back" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginLeft="6dp" android:layout_alignParentBottom="true" android:layout_alignStart="@+id/button_tuichu" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView7" android:src="@drawable/signup" android:layout_alignBottom="@+id/imageView3" android:layout_alignEnd="@+id/relativeLayout2" /> </RelativeLayout>
Register:
package com.b140414.njupt.checkins; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast; import bmob_table.User; import cn.bmob.v3.listener.SaveListener; public class Register extends AppCompatActivity { private EditText register_account_et; private EditText register_password_et; private EditText password_again_et; private EditText realName_et; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); register_account_et= (EditText) findViewById(R.id.register_account_et); register_password_et=(EditText)findViewById(R.id.register_password_et); password_again_et=(EditText)findViewById(R.id.password_again_et); realName_et=(EditText)findViewById(R.id.realName_et); } public void register_sure(View view){ String register_password=register_password_et.getText().toString(); String password_again=password_again_et.getText().toString(); String register_account=register_account_et.getText().toString(); String realName=realName_et.getText().toString(); if(!register_password.equals(password_again)){ Toast.makeText(Register.this,"两次输入的密码不一致,请重新输入!",Toast.LENGTH_LONG).show(); } else if(register_account.isEmpty()||register_account.length()!=11){ Toast.makeText(Register.this,"输入手机号不合法,请重新输入!",Toast.LENGTH_LONG).show(); }else if(realName.isEmpty()){ Toast.makeText(Register.this,"请输入您的真实姓名!",Toast.LENGTH_LONG).show(); }else{ User user=new User(); user.setAccount(register_account); user.setPassword(password_again); user.setRealName(realName); user.save(Register.this,new SaveListener() { @Override public void onSuccess() { Toast.makeText(Register.this,"注册成功,请返回登录!",Toast.LENGTH_LONG).show(); } @Override public void onFailure(int i, String s) { Toast.makeText(Register.this,"注册失败,请重试!",Toast.LENGTH_LONG).show(); } }); } } public void register_quit_btn(View view){ finish(); } }
学生界面:
activity_scan.XML:
<?xml version="1.0" encoding="utf-8"?> <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.b140414.njupt.checkins.ScanActivity" android:background="@drawable/background"> <ListView android:layout_width="wrap_content" android:layout_height="120dp" android:id="@+id/listView" android:layout_alignParentTop="true" android:layout_alignParentStart="true" /> <Button android:layout_width="200dp" android:layout_height="wrap_content" android:text="刷新" android:id="@+id/button3" android:onClick="netScan" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:background="@drawable/circle" android:layout_below="@+id/listView" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="请选择一个wifi" android:id="@+id/textView_choice" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_below="@+id/Wifi_name" android:layout_centerHorizontal="true" /> <Button android:layout_width="100dp" android:layout_height="40dp" android:text="签到" android:id="@+id/Scan_check" android:onClick="Scan_Dao" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:background="@drawable/circle" android:layout_alignTop="@+id/button_scaninfo" android:layout_toStartOf="@+id/Wifi_name" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/Wifi_name" android:layout_below="@+id/button3" android:layout_centerHorizontal="true" android:layout_marginTop="100dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" /> <Button android:layout_width="100dp" android:layout_height="40dp" android:text="签退并退出" android:id="@+id/button_scanquit" android:onClick="Scanquit" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:background="@drawable/circle" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> <Button android:layout_width="100dp" android:layout_height="40dp" android:text="本人记录" android:id="@+id/button_scaninfo" android:onClick="Info_ScanDao" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:background="@drawable/circle" android:layout_marginTop="27dp" android:layout_below="@+id/textView_choice" android:layout_alignStart="@+id/Wifi_name" /> <EditText android:layout_width="100dp" android:layout_height="wrap_content" android:id="@+id/editText_s_key" android:background="@drawable/abc_textfield_search_material" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_below="@+id/textView7" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="签到口令" android:id="@+id/textView7" android:textSize="20dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_below="@+id/button3" android:layout_centerHorizontal="true" android:layout_marginTop="30dp" /> </RelativeLayout>
ScanActivity:
package com.b140414.njupt.checkins; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast; import bmob_table.User; import cn.bmob.v3.listener.SaveListener; public class Register extends AppCompatActivity { private EditText register_account_et; private EditText register_password_et; private EditText password_again_et; private EditText realName_et; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_register); register_account_et= (EditText) findViewById(R.id.register_account_et); register_password_et=(EditText)findViewById(R.id.register_password_et); password_again_et=(EditText)findViewById(R.id.password_again_et); realName_et=(EditText)findViewById(R.id.realName_et); } public void register_sure(View view){ String register_password=register_password_et.getText().toString(); String password_again=password_again_et.getText().toString(); String register_account=register_account_et.getText().toString(); String realName=realName_et.getText().toString(); if(!register_password.equals(password_again)){ Toast.makeText(Register.this,"两次输入的密码不一致,请重新输入!",Toast.LENGTH_LONG).show(); } else if(register_account.isEmpty()||register_account.length()!=11){ Toast.makeText(Register.this,"输入手机号不合法,请重新输入!",Toast.LENGTH_LONG).show(); }else if(realName.isEmpty()){ Toast.makeText(Register.this,"请输入您的真实姓名!",Toast.LENGTH_LONG).show(); }else{ User user=new User(); user.setAccount(register_account); user.setPassword(password_again); user.setRealName(realName); user.save(Register.this,new SaveListener() { @Override public void onSuccess() { Toast.makeText(Register.this,"注册成功,请返回登录!",Toast.LENGTH_LONG).show(); } @Override public void onFailure(int i, String s) { Toast.makeText(Register.this,"注册失败,请重试!",Toast.LENGTH_LONG).show(); } }); } } public void register_quit_btn(View view){ finish(); } }
教师界面:
activity_main.XML:
<?xml version="1.0" encoding="utf-8"?> <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.b140414.njupt.checkins.MainActivity" android:background="@drawable/background"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="欢迎使用" android:id="@+id/textView_title" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:textSize="20dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" /> <Button android:layout_width="150dp" android:layout_height="40dp" android:text="退出" android:id="@+id/button_tui" android:background="@drawable/circle" android:textSize="15dp" android:onClick="Quit" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginBottom="47dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/hello" android:textSize="15dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_marginTop="20dp" android:layout_marginLeft="40dp" android:layout_below="@+id/textView_title" android:layout_alignParentStart="true" /> <RelativeLayout android:layout_width="200dp" android:layout_height="100dp" android:id="@+id/relativeLayout3" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="135dp"> <Button android:layout_width="100dp" android:layout_height="30dp" android:text="离场信息" android:id="@+id/button_li" android:background="@drawable/circle" android:textSize="15dp" android:onClick="LiChang" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_alignParentBottom="true" android:layout_alignParentEnd="true" /> <Button android:layout_width="100dp" android:layout_height="30dp" android:text="点名" android:id="@+id/button_call" android:background="@drawable/circle" android:textSize="15dp" android:onClick="call" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_alignParentBottom="true" android:layout_alignParentStart="true" /> <EditText android:layout_width="100dp" android:layout_height="wrap_content" android:id="@+id/editText_key" android:background="@drawable/abc_textfield_search_material" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_below="@+id/textView6" android:layout_centerHorizontal="true" android:layout_marginTop="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="签到口令" android:id="@+id/textView6" android:textSize="20dp" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" /> </RelativeLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView5" android:src="@drawable/qiandao" android:layout_marginLeft="-20dp" android:layout_above="@+id/hello" android:layout_toEndOf="@+id/textView_title" /> <ListView android:layout_width="wrap_content" android:layout_height="120dp" android:id="@+id/listView2" android:layout_below="@+id/hello" /> <Button android:layout_width="wrap_content" android:layout_height="30dp" android:text="刷新" android:id="@+id/button2" android:onClick="netScan_t" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:background="@drawable/circle" android:layout_below="@+id/listView2" android:layout_alignParentStart="true" android:layout_marginTop="20dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="请选择一个wifi" android:id="@+id/textView_BSSID" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_alignBottom="@+id/button2" android:layout_alignEnd="@+id/listView2" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView_SSID" android:textColor="@color/abc_primary_text_disable_only_material_dark" android:layout_above="@+id/textView_BSSID" android:layout_toEndOf="@+id/relativeLayout3" android:layout_marginStart="11dp" /> </RelativeLayout>
MainActivity:
package com.b140414.njupt.checkins; import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.net.wifi.ScanResult; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.EditText; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; import android.widget.Toast; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import bmob_table.Leave_table; import bmob_table.ScanCheck; import service.WifiCheck_ch; import cn.bmob.v3.BmobQuery; import cn.bmob.v3.listener.FindListener; public class MainActivity extends AppCompatActivity { private TextView hello; public static String BSSID; public String realName ; public String account ; private List<Leave_table> leave_half = new ArrayList<Leave_table>(); private Intent bindIntent; private WifiManager wifiManager; private ListView listView; private TextView textview_choice; private TextView textview_wifiname; private String Key; private EditText editText_key; TextView text1; TextView text2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); hello = (TextView) findViewById(R.id.hello); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); realName = bundle.getString("realName"); account = bundle.getString("account"); hello.setText("你好," + realName); //BindService传入账号与姓名信息 bindIntent = new Intent(MainActivity.this,WifiCheck_ch.class); bindIntent.putExtra("account",account); bindIntent.putExtra("name",realName); listView = (ListView)findViewById(R.id.listView2); textview_choice = (TextView)findViewById(R.id.textView_BSSID); textview_wifiname = (TextView)findViewById(R.id.textView_SSID); editText_key = (EditText)findViewById(R.id.editText_key); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> l, View v, int position,long id) { text1=(TextView)v.findViewById(R.id.BSSID); text2=(TextView)v.findViewById(R.id.SSID); BSSID = text1.getText().toString(); textview_choice.setText(BSSID); textview_wifiname.setText(text2.getText().toString()); } }); wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE); } //获取MAC public String getLocalMacAddress() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress(); } //获取链接的wifi的MAC地址 public String getLinkMacAddress() { WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getBSSID(); } //点名按钮事件 public void call(View view){ BmobQuery<ScanCheck> query1 = new BmobQuery<>(); BmobQuery<ScanCheck> query2 = new BmobQuery<>(); BmobQuery<ScanCheck> query3 = new BmobQuery<>(); Key = editText_key.getText().toString(); //获取当前时间 Date todaydate=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd"); final String s = format.format(todaydate); //当前时间与check_table表中的签到时间进行匹配 //query1.addWhereEqualTo("DaoTime", s); query2.addWhereEqualTo("BSSID", BSSID); query3.addWhereEqualTo("Key",Key); List<BmobQuery<ScanCheck>> andQuerys = new ArrayList<BmobQuery<ScanCheck>>(); andQuerys.add(query1); andQuerys.add(query2); andQuerys.add(query3); BmobQuery<ScanCheck> query_and = new BmobQuery<>(); query_and.and(andQuerys); query_and.findObjects(MainActivity.this, new FindListener<ScanCheck>() { @Override public void onSuccess(List<ScanCheck> qianDao) { String str = ""; for (ScanCheck a : qianDao) { str += a.getRealName() + "\n\n"; } String str1 = "查询成功:共" + qianDao.size() + "个人签到。"; AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(s +"\n"+ Key + "的签到人员详情"); builder.setMessage(str + str1); builder.create().show(); } @Override public void onError(int i, String s) { Toast.makeText(MainActivity.this, "查询失败!" + s, Toast.LENGTH_LONG); } }); } //查看离场信息 public void LiChang(View view) { BmobQuery<Leave_table> query2 = new BmobQuery<>(); BmobQuery<Leave_table> query1 = new BmobQuery<>(); //获取当前时间 Date todaydate = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String s = format.format(todaydate); //当前时间与leave_table表中的leavetype+时间 && BSSID 进行匹配 query2.addWhereEqualTo("LeaveType", "中途离场"+s); query1.addWhereEqualTo("BSSID", BSSID); List<BmobQuery<Leave_table>> andQuerys = new ArrayList<BmobQuery<Leave_table>>(); andQuerys.add(query1); andQuerys.add(query2); BmobQuery<Leave_table> query_and = new BmobQuery<>(); query_and.and(andQuerys); query_and.findObjects(MainActivity.this, new FindListener<Leave_table>() { @Override public void onSuccess(List<Leave_table> leave) { String str = ""; for (Leave_table sjk : leave) { Boolean hasName = false; for(Leave_table bd : leave_half){ if(sjk.getRealName().equals(bd.getRealName())) { hasName = true; break; } } if(!hasName){ leave_half.add(sjk); } } for (Leave_table a : leave_half) { str += a.getRealName() + "\n\n"; } String str1 = "查询成功:共" + leave_half.size() + "个人中途离场。"; AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); Date todaydate = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String s = format.format(todaydate); builder.setTitle(s + "的中途离场人员详情"); builder.setMessage(str + str1); builder.create().show(); } @Override public void onError(int i, String s) { Toast.makeText(MainActivity.this, "查询失败!" + s, Toast.LENGTH_LONG); } }); } public void Quit(View view) { finish(); } public void netScan_t(View v){ List<Map<String, Object>> list; //启动扫描 wifiManager.startScan(); //获取扫描结果 list = getListForSimpleAdapter(); SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.wifiinfo, new String[] { "SSID", "BSSID" }, new int[] { R.id.SSID,R.id.BSSID }); listView.setAdapter(adapter); } private List<Map<String, Object>> getListForSimpleAdapter() { List<ScanResult> mData= wifiManager.getScanResults(); List<Map<String,Object>> list=new ArrayList<Map<String,Object>>(); for (ScanResult a : mData) { Map<String, Object> map = new HashMap<String, Object>(); map = new HashMap<String, Object>(); map.put("SSID", a.SSID); map.put("BSSID", a.BSSID); list.add(map); } return list; } }
至于界面的图片啊啥的,可以去git上下载我的整个工程来获取:https://github.com/ZzzSimon/Checkins
未完待续……
安卓基于WifiScanner的签到APP的更多相关文章
- 安卓学习之学生签到APP(一)
一.学生定位签到页面 具体实现步骤: 1.1 高德地图申请key 1.创建新应用 进入高德地图api控制台,创建一个新应用.如果您之前已经创建过应用,可直接跳过这个步骤. 2.添加新Key 在创建的应 ...
- 基于webview的Hybrid app和React Native及html5
基于webview的Hybrid app和React Native及html5 React Native 结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iO ...
- Windows环境中,通过Charles工具,抓取安卓手机、苹果手机中APP应用的http、https请求包信息
Windows环境中,通过Charles工具,抓取安卓手机.苹果手机中APP应用的http.https请求包信息1.抓取安卓手机中APP应用的http请求包信息1)在电脑上操作,查看Windows机器 ...
- 安卓基于谷歌串口api进行串口开发
准备材料 AndroidStudio 谷歌android-serialport-api 前情提要 网上提供很多基于c语言对安卓串口开发,有jni.cmake等等,不过都太高深,谷歌提供的api已经可以 ...
- 谷歌发布基于机器学习的Android APP安全检测系统:Google Play Protect
Google Play作为众所周知的在线应用市场,因为审查制度的松散,经常会有一些恶意软件伪装成其他应用混入其中.此前阿里聚安全小编就报道了2例关于恶意软件伪装在Google Play上的事件:< ...
- 一个基于NodeJS开发的APP管理CMS系统
花了大概3周独立开发了一个基于NodeJS的CMS系统,用于公司APP的内容管理( **公司APP?广告放在最后 ^_^ ** ,管理员请理解~~~ )晚上看了部电影还不想睡,闲着也是闲着就作下小小总 ...
- 微信APP支付(基于Java实现微信APP支付)
步骤: 导入maven依赖 <!--微信支付--> <dependency> <groupId>com.github.wxpay</groupId> & ...
- RF Analyzer for Android 安卓平台连接HackRF的App
Over the last week I've been working on a new project, trying to build a spectrum analyzer for Andro ...
- 把安卓源代码中的system app独立出来,像开发普通app那样开发
个人建议首先依照android源码的ide/eclipse中的格式化xml和import导入到你编译的eclipse中,假设你编译的android源码是2.3以上的版本号的,建议用JDK6 ...
随机推荐
- c++中的内存空间不足和自定义处理内存不足
new操作符动态分配内存时,首先它会调用对象的operator new()函数分配相应大的内存(如果对象类没有重载operator new()函数,则默认调用<new>头文件里的opera ...
- css实现自适应屏幕高度;
css实现自适应屏幕高度: <!DOCTYPE html><html lang="en"><head> <meta charset=&qu ...
- MySql中常用的hint
对于经常使用Oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在MySQL里,也有类似的hint功能.下面介绍一些常用的. 强制索引 FORCE ...
- cuda-convnet windows8下编译
编译环境: windows8.1 Anaconda python2.7 Visual studio 2012 CUDA6.0 Pthread for windows Intel Math Kernel ...
- centos虚拟机网络配置
修改IP vi /etc/sysconfig/network-scripts/ifcfg-eth0 ONBOOT=yes BOOTPROTO=dhcp service network restart ...
- 安装和配置CentOS时钟同步服务
Type the following command to install ntp: # yum install -y ntp Turn on service: # chkconfig ntpd on ...
- 为模版设计师而生的Twig(下)-Twig使用指南
原文地址:http://my.oschina.net/veekit/blog/276800 12. 模板继承 Twig最强大的部分是模板继承.模板继承允许你建立一个基本的"骨架"模 ...
- 关于Maven的一些记录
Eclipse-Mars4.5自带Maven插件,自己重新下载之后将不兼容. 可以在图中位置设置jar包路径. 可以在Eclipse新建Dynamic Web Project项目,然后在项目上右键=& ...
- <<软技能,代码之外的生存技能>>读书笔记
管理 1. 制定大目标,再分解成小目标,定时反思自己的长期和短期的成果 2. 人都希望自己很重要, 要让下属有存在感,让他们做事有成就感 3. 奖励积极比惩罚消极更有用 4. 学会换位思考,不要用&q ...
- 【MySQL】漫谈MySQL中的事务及其实现
最近一直在做订单类的项目,使用了事务.我们的数据库选用的是MySQL,存储引擎选用innoDB,innoDB对事务有着良好的支持.这篇文章我们一起来扒一扒事务相关的知识. 为什么要有事务? 事务广泛的 ...