zoukankan      html  css  js  c++  java
  • androidcookie存储sqllite

    /**声明一些数据库操作的常量*/
      private static SQLiteDatabase mDatabase = null;
      private static final String DATABASE_FILE = "webview.db";
      private static final String COOKIES_NAME_COL = "name";
      private static final String COOKIES_VALUE_COL = "value";
      private static final String COOKIES_DOMAIN_COL = "domain";
      private static final String COOKIES_PATH_COL = "path";
      private static final String COOKIES_EXPIRES_COL = "expires";
      private static final String COOKIES_SECURE_COL = "secure";
    mDatabase = LoginApiActivity.this.openOrCreateDatabase(DATABASE_FILE, 0, null);
    //创建cookie数据库
        if (mDatabase != null) {
          // cookies
          mDatabase.execSQL("CREATE TABLE IF NOT EXISTS cookies "
                  + " (_id INTEGER PRIMARY KEY, "
                  + COOKIES_NAME_COL + " TEXT, " + COOKIES_VALUE_COL
                  + " TEXT, " + COOKIES_DOMAIN_COL + " TEXT, "
                  + COOKIES_PATH_COL + " TEXT, " + COOKIES_EXPIRES_COL
                  + " INTEGER, " + COOKIES_SECURE_COL + " INTEGER" + ");");
          mDatabase.execSQL("CREATE INDEX IF NOT EXISTS cookiesIndex ON "
                  + "cookies" + " (path)");
        }
      }
     
    /*写cookie*/
      public void addCookie(Cookie cookie) {
        if (cookie.getDomain() == null || cookie.getPath() == null || cookie.getName() == null
                || mDatabase == null) {
            return;
        }
        String mCookieLock = "asd";
        synchronized (mCookieLock) {
            ContentValues cookieVal = new ContentValues();
            cookieVal.put(COOKIES_DOMAIN_COL, cookie.getDomain());
            cookieVal.put(COOKIES_PATH_COL, cookie.getPath());
            cookieVal.put(COOKIES_NAME_COL, cookie.getName());
            cookieVal.put(COOKIES_VALUE_COL, cookie.getValue());
     
            mDatabase.insert("cookies", null, cookieVal);
          
        }
    }

  • 相关阅读:
    sql: 左连接 和内连接区别联系 No
    Maven 浅谈一 No
    日记090212
    js 获取asp 控件DropDownList的选择值,及所有的text和value
    ASP.NET 2.0 只读 TextBox 回发后信息丢失
    Cry On My Shoulder (背景音乐)
    Inside ASP.NET 2.0 DataBound Control 3
    ASP.NET自定义控件复杂属性声明持久性浅析
    Inside ASP.NET 2.0 DataBound Control 2
    ASP.NET 2.0 Client Callback 浅析
  • 原文地址:https://www.cnblogs.com/wcLT/p/8664396.html
Copyright © 2011-2022 走看看