PIXNET Logo登入

經驗交流分享與備忘

跳到主文

感情最痛恨 劈腿. 背叛 與 欺騙

部落格全站分類:數位生活

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 9月 19 週五 201401:37
  • OS X 安裝 ant 指令

在使用 phonegap 執行產品專案時, 使用指令
 
phonegap run platform
 
(繼續閱讀...)
文章標籤

本熊 發表在 痞客邦 留言(0) 人氣(501)

  • 個人分類:Android程式設計
▲top
  • 5月 21 週三 201419:28
  • [轉貼] Load a POST request into a WebView in Android

The standard way to load an URL into a WebView object is using the loadUrl method.

(繼續閱讀...)
文章標籤

本熊 發表在 痞客邦 留言(0) 人氣(1,874)

  • 個人分類:Android程式設計
▲top
  • 5月 21 週三 201416:39
  • [轉貼] Android Programming: Send data via POST to WebView (e.g. to implement an automatic login)

With the following code, it is possible to send data to a WebView using POST with Android:

 






public void onCreate(Bundle savedInstanceState) {

 

    super.onCreate(savedInstanceState);

 

    WebView wv = new WebView(this);

    setContentView(wv);

 

    String url = "http://www.example.com/login.php";

    String data = "name=Test&password=12345";

 

    wv.postUrl(url, EncodingUtils.getBytes(data, "base64"));

}






(繼續閱讀...)
文章標籤

本熊 發表在 痞客邦 留言(0) 人氣(0)

  • 個人分類:Android程式設計
▲top
  • 5月 21 週三 201416:14
  • [轉貼] Call an activity method from a fragment

Q:
Trying to call a method in my activity from a fragment. I want the fragment to give the method data and to get the data when the method return. I want to achieve similar to call on a static method, but without the use of static because it create problems in the activity.
New to fragments so I need an easy and pedagogic explanation!
Thanks!
(繼續閱讀...)
文章標籤

本熊 發表在 痞客邦 留言(0) 人氣(2,771)

  • 個人分類:Android程式設計
▲top
  • 5月 14 週三 201412:29
  • [轉] Android-Bootstrap

做到一种样式  android 的spinner本身背景样式要黑色的 ,而spinner里的字体也是黑色的 ,spinner 控件的属性里设置TextColor没用  网上找了下  需要定义xml 文件来定义样式   和自定义按钮控件类似;
1,首先定义spinenr本身背景的样式:


Java代码  收藏代码



  • <?xml version="1.0" encoding="utf-8"?>  

  • <selector xmlns:android="http://schemas.android.com/apk/res/android">  

  •     <item android:state_pressed="true" android:drawable="@drawable/droplist_down" />  

  •     <item android:state_focused="true" android:drawable="@drawable/droplist_focus" />  

  •     <item android:drawable="@drawable/droplist" />  

  • </selector>  

  • (繼續閱讀...)
    文章標籤

    本熊 發表在 痞客邦 留言(0) 人氣(656)

    • 個人分類:Android程式設計
    ▲top
    • 5月 13 週二 201416:36
    • [轉] Android AppTheme 系統預設樣式android:Theme語法整理

    建立Android Project後會多了res/values/styles.xml的樣式檔案
    事實上這是讓Android讀取的預設的樣式定義檔
    例如要讓整個程式的基本樣式為亮色系或暗色系~
    或者要隱藏標題全螢幕等等, 皆可以在這個檔案上進行修改...
    (繼續閱讀...)
    文章標籤

    本熊 發表在 痞客邦 留言(0) 人氣(2,173)

    • 個人分類:Android程式設計
    ▲top
    • 3月 31 週一 201400:40
    • [轉帖] 在Android中使用顏色的方法

    在Android中創建或表示一個顏色的方法
    1. 使用Color類的常量,如:
    int color = Color.BLUE; // 創建一個藍色 是使用Android提供的顏色
    (繼續閱讀...)
    文章標籤

    本熊 發表在 痞客邦 留言(0) 人氣(246)

    • 個人分類:Android程式設計
    ▲top
    • 12月 21 週六 201304:02
    • Convert String to Uri


    You can use the parse static method from Uri

    Uri myUri =Uri.parse("http://stackoverflow.com")
    (繼續閱讀...)
    文章標籤

    本熊 發表在 痞客邦 留言(0) 人氣(3)

    • 個人分類:Android程式設計
    ▲top
    • 12月 21 週六 201302:47
    • [轉貼] 一個可以接web service回應的Android HTTP client


    在瀏覽器裡頭有實做AJAX query,這讓網頁有了更大的發揮空間,
    程式人員可以讓網頁就像一般應用程式一樣有趣。
    那如果,一般應用程式也可以發出HTTP query,

    進而取得web service吐出的東西,那又會擦出怎樣的火花呢? 先賣個關子~
    本篇只講在Android上,要如何寫一個發出HTTP query,又接回HTTP response的程式。
    關鍵字:Android & HttpClient
    在Android SDK裡有引入org.apache.http.client,
    這package是這程式的靈魂,詳情可以看本篇的參考。
    底下是程式:
    流程:
    1.建一個text view
    2.呼叫HTTPGetQuery
    2.1.建一個HTTP client
    2.2.建一個HTTP get物件,並在初始化的參數帶入URL
    2.3.建一個HTTP reponse handler物件
    2.4.HTTP client實際對web service query,並帶入HTTP get
    2.5.取回reponse,再從response取出status code、header、cookie、content字串
    2.6.因為HTTP是socket IO,所以用try catch包起來,以防IO錯誤時沒有處理到
    2.7.回傳結果
    3.將結果放到text view
    4.畫出這個程式畫面
    程式碼:
    package androidajax.example.android;
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import org.apache.http.Header;
    import org.apache.http.HttpResponse;
    import org.apache.http.NameValuePair;
    import org.apache.http.client.*;
    import org.apache.http.client.entity.UrlEncodedFormEntity;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.apache.http.message.BasicNameValuePair;
    import org.apache.http.protocol.HTTP;
    import org.apache.http.util.EntityUtils;
    public class AndroidAJAX extends Activity {
        private Document xmldoc;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Have a text view on the scene.
            TextView tv = new TextView(this);
            // Put the answer string returned by the HTTP query on the scene.
            // Change the red url by yourself.
            Map map = HTTPGetQuery("http://test.com.url?account=牛蛙");
            //Map map = HTTPPostQuery("http://test.com.url");
            tv.setText(map.get("status").toString() + ": " + map.get("content").toString());
            // Render the scene.
            setContentView(tv);
        }
        
        /** Method: Do the HTTP query according to hostURL with "get" method. */
        private Map<String, String> HTTPGetQuery(String hostURL) {
            // Declare a content string prepared for returning.
            String content = "";
            // Have an HTTP client to connect to the web service.
            HttpClient httpClient = new DefaultHttpClient();
            // Have an HTTP response container.
            HttpResponse httpResponse = null;
            // Have map container to store the information.
            Map<String, String> map = new HashMap<String, String>();
            
            // This try & catch is prepared for the IO exception in case.
            try {
                // Have a post method class with the query URL.
                HttpGet httpQuery = new HttpGet(hostURL);
                // The HTTP client do the query and have the string type response.
                httpResponse = httpClient.execute(httpQuery);
                
                // Read the HTTP headers and into content.
                //for (Header header : httpResponse.getAllHeaders()) {
                //     content += "\n" + header.toString();
                //}
                // Read the HTTP response content as an encoded string.
                content += EntityUtils.toString(httpResponse.getEntity());
            }
            // Catch the HTTP exception.
            catch(ClientProtocolException ex) {
                content = "ClientProtocolException:" + ex.getMessage();
            }
            // Catch the any IO exception.
            catch(IOException ex) {
                content = "IOException:" + ex.getMessage();
            }
            // The HTTP connection must be closed any way.
            finally    {
                httpClient.getConnectionManager().shutdown();
            }
            
            // Check the HTTP connection is executed or not.
            if (httpResponse != null) {
                // Put the status code with status key.
                map.put("status", Integer.toString(httpResponse.getStatusLine().getStatusCode()));
                // Put the response content with content key
                map.put("content", content);
            }
            else {
                // Put the dummy with status key.
                map.put("status", "");
                // Put the dummy with content key
                map.put("content", "");
            }
            
            // Return result.
            return map;
        }
        
        /** Method: Do the HTTP query according to hostURL with "post" method. */
        private Map<String, String> HTTPPostQuery(String hostURL) {
            // Declare a content string prepared for returning.
            String content = "";
            // Have an HTTP client to connect to the web service.
            HttpClient httpClient = new DefaultHttpClient();
            // Have an HTTP response container.
            HttpResponse httpResponse = null;
            // Have map container to store the information.
            Map<String, String> map = new HashMap<String, String>();
            
            // This try & catch is prepared for the IO exception in case.
            try {
                // Have a post method class with the query URL.
                HttpPost httpQuery = new HttpPost(hostURL);
                
                // Have a list of key-value pair container.
                List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                // Add the HTTP post arguments into the list.
                pairs.add(new BasicNameValuePair("account", "青蛙"));
                pairs.add(new BasicNameValuePair("password", "frog"));
                // Assign the list as the arguments of post being UTF_8 encoding.
                httpQuery.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8));
                
                // The HTTP client do the query and have the string type response.
                httpResponse = httpClient.execute(httpQuery);
                
                // Read the HTTP response content as an encoded string.
                content += EntityUtils.toString(httpResponse.getEntity());
            }
            // Catch the HTTP exception.
            catch(ClientProtocolException ex) {
                content = "ClientProtocolException:" + ex.getMessage();
            }
            // Catch the any IO exception.
            catch(IOException ex) {
                content = "IOException:" + ex.getMessage();
            }
            // The HTTP connection must be closed any way.
            finally    {
                httpClient.getConnectionManager().shutdown();
            }
            
            // Check the HTTP connection is executed or not.
            if (httpResponse != null) {
                // Put the status code with status key.
                map.put("status", Integer.toString(httpResponse.getStatusLine().getStatusCode()));
                // Put the response content with content key.
                map.put("content", content);
            }
            else {
                // Put the dummy with status key.
                map.put("status", "");
                // Put the dummy with content key.
                map.put("content", "");
            }
            
            // Return result.
            return map;
        }
    }
    因為用到HTTP client,這會需要用到網路IO,需要權限授權,
    所以要改 res/AndroidManifest.xml
    我在</APPLICATION>下加上:
        <uses-permission android:name="android.permission.INTERNET" />
    參考:
    Android 上的 HTTP 服務相關函式:
        http://ysl-paradise.blogspot.com/2008/09/android-http-i.html
        http://ysl-paradise.blogspot.com/2008/09/android-http-ii.html
        http://ysl-paradise.blogspot.com/2008/09/android-http-iii.html
    HttpClient Examples:
        http://hc.apache.org/httpcomponents-client-ga/examples.html
        http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientWithResponseHandler.java
    Permission denied error while call webservice using HTTP in android:
        http://stackoverflow.com/questions/3932129/permission-denied-error-while-call-webservice-using-http-in-android-application
     
    本文取自 http://blog.xuite.net/zack_pan/blog/47887919
    (繼續閱讀...)
    文章標籤

    本熊 發表在 痞客邦 留言(0) 人氣(1,964)

    • 個人分類:Android程式設計
    ▲top
    • 12月 21 週六 201302:13
    • [轉貼] 禁止屏幕随手机旋转变化 及 避免在转屏时重启Activity





    禁止屏幕随手机旋转变化



    有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变化:
    在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入 android:screenOrientation=”landscape” 属性。






    (繼續閱讀...)
    文章標籤

    本熊 發表在 痞客邦 留言(0) 人氣(210)

    • 個人分類:Android程式設計
    ▲top
    1

    參觀人氣

    • 本日人氣:
    • 累積人氣:

    文章分類

    toggle 作業系統相關 (9)
    • FreeBSD (8)
    • IPv6 Logo (2)
    • Visual C# (1)
    • Visual C# (1)
    • Mac使用心得 (5)
    • Synology NAS應用 (0)
    • 系統應用 (49)
    • 防毒防駭 (5)
    • 系統安裝 (30)
    toggle 投資理財 (2)
    • 科技產業 (8)
    • 投資學習 (9)
    toggle 網頁設計相關 (6)
    • Flex程式設計 (5)
    • MySQL資料庫 (13)
    • ASP.NET程式設計 (1)
    • CSS樣式表應用 (5)
    • Flex (1)
    • PHP程式設計 (51)
    • Perl 程式設計 (1)
    • Windows系統應用 (2)
    • 好書推件 (1)
    • Android程式設計 (10)
    • C程式設計 (2)
    • Linux相關應用 (18)
    • Java程式設計 (6)
    • JAVAt程式設計-GWT (7)
    • Eucalyptus XEN (2)
    • 喻道故事 (1)
    • 下載資源 (2)
    • 終生學習 (7)
    • Goolge 新玩意 (1)
    • 英文學習心得 (3)
    • 工商服務 (12)
    • 勵志成長 (18)
    • 新聞時事 (17)
    • 讀者服務 (3)
    • JavaScript (22)
    • 省錢大作戰 (15)
    • 搶錢大作戰 (2)
    • 趣味分享 (50)
    • 感情生活 (15)
    • 用DSLR寫日記 (20)
    • 程式設計 (7)
    • 職場人生 (16)
    • 健康生活 (63)
    • 未分類文章 (1)