2016年10月11日 星期二

CORDOVA打包APP的cookie問題


用cordova打包html+js成APP時發現android不能存取cookie..找到下面文章參考解決

該檔案位置似乎版本不同不一定在那?

我的位置是在專案底下的"\platforms\android\src\io\cordova"裡面有個資料夾打開就會看到。

另外要注意的是修改好該檔案後存檔完記得關閉,不然再打包途中會出現說該檔案已修改..之後打包出來的APP會有些BUG跟問題...

用jquery的cookie也適用此方法。

參考網址:http://aubreyhsu.blogspot.tw/2015/05/documentcookie-dont-work-in-android.html

在利用cordova打包html和js時,發現document.cookie竟然寫不進手機裡,查資料才知道在android 3.1以上需要打開cookie寫入,操作如下:
1、打開專案底下的「\platforms\android\src\com\example\MainActivity.java」:
2、先「import android.webkit.CookieManager;」,
3、在 onCreate function裡面「CookieManager.setAcceptFileSchemeCookies(true);

範例如下:
import android.os.Bundle;
import android.webkit.CookieManager;
import org.apache.cordova.*;

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        CookieManager.setAcceptFileSchemeCookies(true);
        super.onCreate(savedInstanceState);
        // Set by <content src="index.html" /> in config.xml
        loadUrl(launchUrl);
    }
}

2016年9月22日 星期四

建立給apk使用的金鑰

公司需求開始開發app的東西..做了apk之後安裝發現得產生金鑰來使用..所以找了些文章參考..

大概整理一下如下:
以下資料參考來源:https://taco.visualstudio.com/en-us/docs/tutorial-package-publish-readme/ 

Generate a private key

To sign your app, create a keystore. A keystore is a binary file that contains a set of private keys. Here's how you create one.
  1. Open a Command Prompt in administrator mode.
  2. In the Command Prompt, change directories to the %JAVA_HOME%\bin folder.
    (For example: C:\Program Files (x86)\Java\jdk1.7.0_55\bin).
  3. In the Command Prompt, run the following command.
    keytool -genkey -v -keystore c:\my-release-key.keystore -alias johnS
    -keyalg RSA -keysize 2048 -validity 10000
    
    Replace my-release-key.keystore and johnS with names that make sense to you.
  4. You'll be asked to provide a password and the Distinguished Name fields for your key.
    This series of responses gives you an idea of the kinds of information you'll provide for each prompt. Like in the previous command, respond to each prompt with information that makes sense for your app.
    Enter keystore password: pwd123
    Re-enter new password: pwd123
    What is your first and last name?
    [Unknown]= John Smith
    What is the name of your organizational unit?
    [Unknown]= ABC
    What is the name of your organization?
    [Unknown]= XYZ
    What is the name of your of your City or Locality?
    [Unknown]= Redmond
    What is the name of your State or Province?
    [Unknown]= WA
    What is the two-letter country code for this unit?
    [Unknown]= US
    Is CN=John Smith, OU=ABC, O=XYZ, L=Redmond, ST=WA, C=US correct??
    [no]=  y
    
    
    After you provide this information, output like this appears in the Command Prompt.
    Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA)
    with a validity of 10,000 days for: CN= John Smith, OU= ABC, O= XYZ,
    L=Redmond, ST=WA, C=US
    
    Enter key password for <johnS>
        (RETURN if same as keystore password):
    
    The Android SDK generates the keystore as a file named my-release-key.keystore and places that file in the C:\ drive. The keystore contains a single key, valid for 10000 days.
    If you want more detail about this process, see the Android developer documentation here:Signing your applications

照以上步驟後會產生一個key在你指定的位置,之後到apk原碼的資料夾中應該有一個build.json的檔案,打開後把裡面分別照自己設定的填入,照上方範例的話就是

{
 "android": {
     "release": {
         "keystore":"c:\\my-release-key.keystore",
         "storePassword":"pwd123",
         "alias":"johnS",
         "password":"pwd123",
         "keystoreType":""
       }
   }
}
之後打包後安裝就沒金鑰問題了。

2016年5月16日 星期一

CheckBox全選或全不選

找看看如何實作核選方塊的全選與全取消功能時剛好翻到這方法,很簡單就能處理。

原文章可運行測試:
http://www.wowbox.com.tw/blog/article.asp?id=2923

程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CheckBox全選或全不選</title>
<style type="text/css">
p {margin:0;font-size:12px;line-height:26px;}
</style>
<script type="text/javascript">
function check_all(obj,cName)
{
    var checkboxs = document.getElementsByName(cName);
    for(var i=0;i<checkboxs.length;i++){checkboxs[i].checked = obj.checked;}
}
</script>
</head>
 
<body>
<p><input type="checkbox" name="all" onclick="check_all(this,'c')" />全選/全不選</p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
<p><input type="checkbox" name="c" value="" /></p>
</body>
</html>