以上就是给各位分享在ANDROID中通过EMAIL_ADDRESS检索SQLITEDB中的用户名和密码,同时本文还将给你拓展andriod下通过webservice加SQL数据库判断用户名和密码、an
以上就是给各位分享在ANDROID中通过EMAIL_ADDRESS检索SQLITE DB中的用户名和密码,同时本文还将给你拓展andriod下通过webservice 加SQL数据库判断用户名和密码、android – 从“canonical_addresses”表中获取地址、android – 使用Preferences保存用户名和密码、android – 保存Kivy应用程序的登录屏幕用户名和密码等相关知识,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:- 在ANDROID中通过EMAIL_ADDRESS检索SQLITE DB中的用户名和密码
- andriod下通过webservice 加SQL数据库判断用户名和密码
- android – 从“canonical_addresses”表中获取地址
- android – 使用Preferences保存用户名和密码
- android – 保存Kivy应用程序的登录屏幕用户名和密码
在ANDROID中通过EMAIL_ADDRESS检索SQLITE DB中的用户名和密码
public String getEmailAddr() throws sqlException { Cursor mCursor = db.rawQuery( "SELECT Username,Passwords FROM " + USERS_TABLE + " WHERE EmailNO=?",null); if (mCursor != null) { if(mCursor.getCount() > 0 { //return obj1.getpassword(); } } //return false; return obj1.getpassword(); }
当用户输入电子邮件地址时,必须首先检查是否存在,并使用我的活动代码发送电子邮件返回密码和用户名:
public void onClick(View v) { String EmailAddress = txtEmailAddress.getText().toString(); try { if(EmailAddress.length() > 0) { DBAdapter dbUser = new DBAdapter (RecoverPassword.this); dbUser.open(); if(dbUser.getEmailAddress(EmailAddress)) { Toast.makeText(RecoverPassword.this,"Email Successfully ",Toast.LENGTH_LONG).show(); Toast.makeText String to = txtEmailAddress.getText().toString(); //String subject = EmailAddress.getText().toString(); // String message = EmailAddress.getText().toString(); Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL,new String[]{ to}); email.putExtra(Intent.EXTRA_SUBJECT,"Password Recovery"); email.putExtra(Intent.EXTRA_TEXT,dbUser.getEmailAddr()); //need this to prompts email client only email.setType("message/rfc822"); startActivity(Intent.createChooser(email,"gmail :")); } else { Toast.makeText(RecoverPassword.this,"Invalid Email",Toast.LENGTH_LONG).show(); txtEmailAddress.setText(""); } dbUser.close(); } } catch(Exception e) { Toast.makeText(RecoverPassword. this,e.getMessage(),Toast.LENGTH_LONG).show(); } Please help me to check what is wrong...but there is no error but it cant return username and password to the email sent
解决方法
String[] whereArgs = new String[<data>]; Cursor mCursor = db.rawQuery("SELECT Username,Passwords FROM " + USERS_TABLE + " WHERE EmailNO = ?",whereArgs); mCursor.moToFirst(); if(mCursor.getCount() > 0} { String userName = mCursor.getString(0); String password = mCursor.getString(1); }
您必须使用提供从数据库返回数据的Cursor实例的getter.
编辑:
我没有注意到你使用whereArgs所以当你使用WHERE子句时,你必须具体whereArgs as String []包含将被替换的数据而不是?焦炭.
您可以使用Fo关闭数据库:
@Override protected void onDestroy() { super.onDestroy(); if (yourDatabase != null) { yourDatabase.close(); } }
或者在打开数据库的每个工作之后,你应该关闭()db.
andriod下通过webservice 加SQL数据库判断用户名和密码
andriod下通过webservice 加SQL数据库判断登录用户名和密码;请大家帮我检查下,谢谢
下面是MainActivity在下判断,问题主要出在dbUtil.JudgeUserInfo("111","9999", "SL"); 这句的调用里面;
public class MainActivity extends Activity { private Button btnlogin; private DBUtil dbUtil; private boolean lgstate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnlogin=(Button) findViewById(R.id.login); btnlogin.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ setJudgeUser(); if(lgstate==true) { //用户存在打开新窗口 Intent intent=new Intent(); EditText editText=(EditText)findViewById(R.id.et_username); intent.setClass(MainActivity.this, Childmain.class); intent.putExtra("username",editText.getText().toString());//技师编号 startActivityForResult(intent, 0); } else { Toast.makeText(MainActivity.this, "登录失败,用户名或密码有误!", Toast.LENGTH_LONG).show(); } } } /** * 判断传人的用户信息是否正确 */ public void setJudgeUser() { dbUtil.JudgeUserInfo("111","9999", "SL"); lgstate=true; }
下面是DBUtil的代码;
public class DBUtil { private ArrayList<String> arrayList = new ArrayList<String>(); private ArrayList<String> brrayList = new ArrayList<String>(); private ArrayList<String> crrayList = new ArrayList<String>(); private HttpConnSoap Soap = new HttpConnSoap(); public static Connection getConnection() { Connection con = null; try { //Class.forName("org.gjt.mm.mysql.Driver"); //con=DriverManager.getConnection("jdbc:sqlserver://192.168.0.106:3306/test?useUnicode=true&characterEncoding=UTF-8","root","initial"); } catch (Exception e) { //e.printStackTrace(); } return con; } /** * 判断传人的用户信息是否存在 * * @return */ public void JudgeUserInfo(String TechNum, String Anpassword, String CmpCode) { arrayList.clear(); brrayList.clear(); arrayList.add("TechNum"); arrayList.add("Anpassword"); arrayList.add("CmpCode"); brrayList.add(TechNum); brrayList.add(Anpassword); brrayList.add(CmpCode); Soap.GetWebServre("JudgeUserInfo", arrayList, brrayList).getClass(); } }
下面是HttpConnSoap Soap的代码
public class HttpConnSoap { public ArrayList<String> GetWebServre(String methodName, ArrayList<String> Parameters, ArrayList<String> ParValues) { ArrayList<String> Values = new ArrayList<String>(); String ServerUrl = "http://10.10.0.21/Kanglesystem/KlService.asmx"; String soapAction = "http://tempuri.org/" + methodName; String soap = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body />"; String tps, vps, ts; String mreakString = ""; mreakString = "<" + methodName + " xmlns=\"http://tempuri.org/\">"; for (int i = 0; i < Parameters.size(); i++) { tps = Parameters.get(i).toString(); //设置该方法的参数为.net webService中的参数名称 vps = ParValues.get(i).toString(); ts = "<" + tps + ">" + vps + "</" + tps + ">"; mreakString = mreakString + ts; } mreakString = mreakString + "</" + methodName + ">"; /* +"<HelloWorld xmlns=\"http://tempuri.org/\">" +"<x>string11661</x>" +"<SF1>string111</SF1>" + "</HelloWorld>" */ String soap2 = "</soap:Envelope>"; String requestData = soap + mreakString + soap2; try { URL url = new URL(ServerUrl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); byte[] bytes = requestData.getBytes("utf-8"); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setConnectTimeout(6000);// 设置超时时间 con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "text/xml;charset=utf-8"); con.setRequestProperty("SOAPAction", soapAction); con.setRequestProperty("Content-Length", "" + bytes.length); OutputStream outStream = con.getOutputStream(); outStream.write(bytes); outStream.flush(); outStream.close(); InputStream inStream = con.getInputStream(); Values = inputStreamtovaluelist(inStream, methodName); return Values; } catch (Exception e) { return null; } } public ArrayList<String> inputStreamtovaluelist(InputStream in, String MonthsName) throws IOException { StringBuffer out = new StringBuffer(); String s1 = ""; byte[] b = new byte[4096]; ArrayList<String> Values = new ArrayList<String>(); Values.clear(); for (int n; (n = in.read(b)) != -1;) { s1 = new String(b, 0, n); out.append(s1); } System.out.println(out); String[] s13 = out.toString().split("><"); String ifString = MonthsName + "Result"; String TS = ""; String vs = ""; Boolean getValueBoolean = false; for (int i = 0; i < s13.length; i++) { TS = s13[i]; System.out.println(TS); int j, k, l; j = TS.indexOf(ifString); k = TS.lastIndexOf(ifString); if (j >= 0) { System.out.println(j); if (getValueBoolean == false) { getValueBoolean = true; } else { } if ((j >= 0) && (k > j)) { System.out.println("FFF" + TS.lastIndexOf("/" + ifString)); l = ifString.length() + 1; vs = TS.substring(j + l, k - 2); Values.add(vs); System.out.println("退出" + vs); getValueBoolean = false; return Values; } } if (TS.lastIndexOf("/" + ifString) >= 0) { getValueBoolean = false; return Values; } if ((getValueBoolean) && (TS.lastIndexOf("/" + ifString) < 0) && (j < 0)) { k = TS.length(); vs = TS.substring(7, k - 8); Values.add(vs); } } return Values; } }
android – 从“canonical_addresses”表中获取地址
content://mms-sms/conversations?simple=true
现在我想使用收件人ID从canonical_addresses“表中获取地址.但我不知道查询canonical_addresses表”.我在网上搜索了很多.请帮我找个解决方案的朋友.
解决方法
recipient_ids.split(“”)
并查找每个id.
getContentResolver().query(Uri.parse("content://mms-sms/canonical-addresses"),null,"_id = " + recipientId,null);
要么
getContentResolver().query(Uri.parse("content://mms-sms/canonical-address/" + recipientId),null);
android – 使用Preferences保存用户名和密码
我在使用“首选项”在我的应用程序中保存数据登录时遇到了麻烦.我已经在第一时间保存了用户名和密码,但下次我不知道如何在填写的字段用户名后保存自动填充/自动填充密码.有谁能够帮我. Thanx这么多.
解决方法:
试试这段代码这会对你有所帮助:)
// Get SharedPreferences
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
// set UI
EditText username = (EditText) findViewById(R.id.username);
EditText password = (EditText) findViewById(R.id.username);
// get value from existing preference
strusername = sharedPreferences.getString("username", "");
strpassword = sharedPreferences.getString("password", "");
// set existing value
username.setText(strusername);
password.setText(strpassword);
findViewById(R.id.login).setonClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// put value in preference on button click
Editor editor = sharedPreferences.edit();
editor.putString("username", username.getText().toString());
editor.putString("password", password.getText().toString());
editor.commit();
}
});
android – 保存Kivy应用程序的登录屏幕用户名和密码
我已经在App类中添加了一个on_pause方法,但这只会让用户在应用程序关闭但未被杀死时保持登录状态.是否有最佳实践可以安全地允许持久用户使用Kivy登录,即使应用程序被杀死后也是如此?
编辑:我更喜欢适用于Android应用和iOS应用的单一Kivy解决方案,无需编辑/添加iOS或Android特定代码.
解决方法
from kivy.storage.jsonstore import JsonStore from os.path import join class AppScreen(ScreenManager): data_dir = App().user_data_dir store = JsonStore(join(data_dir,''storage.json'')) ... def login(self): username = self.login_username.text password = self.login_password.text AppScreen.store.put(''credentials'',username=username,password=password)
这是检索凭据的代码:
try: store.get(''credentials'')[''username''] except KeyError: username = "" else: username = store.get(''credentials'')[''username''] try: store.get(''credentials'')[''password''] except KeyError: password = "" else: password = store.get(''credentials'')[''password'']
在.kv文件中,用户名和密码TextInput小部件如下所示:
TextInput: id: login_username text: root.username on_enter_key: root.login() TextInput: id: login_password text: root.password on_enter_key: root.login()
今天关于在ANDROID中通过EMAIL_ADDRESS检索SQLITE DB中的用户名和密码的介绍到此结束,谢谢您的阅读,有关andriod下通过webservice 加SQL数据库判断用户名和密码、android – 从“canonical_addresses”表中获取地址、android – 使用Preferences保存用户名和密码、android – 保存Kivy应用程序的登录屏幕用户名和密码等更多相关知识的信息可以在本站进行查询。
本文标签: