顯示具有 Android 標籤的文章。 顯示所有文章
顯示具有 Android 標籤的文章。 顯示所有文章

2015年7月6日 星期一

android藍牙傳輸(一)

藍牙IEEE 802.15是一種低功耗、低成本的主從式短距無線傳輸通道,目前已經成為行動手持裝置與配件設備之間的標準無線通訊介面。藍牙提供行動裝置與配件之間,可進行非同步資料傳輸及同步語音傳輸。在Android中藍牙傳輸作業主要由以下類別進行處理:
BluetoothAdapter:藍牙適配器,代表本機運行的藍牙設備
BluetoothDevice:遠端藍牙設備。
BluetoothSocket:與遠端藍牙裝置之通訊介面。

BluetoothServerSocket:用來監聽來自遠端設備送來的Bluetooth Sockets。

UUID是由一組128位元的16進位數字所構成,用來提供資訊裝置服務唯一的識別碼。UUID的標準型式包含32個16進位數字,以連字號分為五段,形式為8-4-4-4-12的32個字元。使用標準藍牙通訊協定之藍牙裝置UUID為fa87c0d0-afac-11de-8a39-0800200c9a66,如果要將藍牙裝置當作串列接口協定,則UUID要設為00001101-0000-1000-8000-00805F9B34FB


2015年4月7日 星期二

Android Studio - 變更應用程式圖示

Android Studio預設會使用Android頭像圖樣作為應用程式圖示。要變更應用程式圖示,由File功能表選取New…/Image Asset命令開啟Asset Studio工具程式來建立圖示資源。


l  Asset Type欄選擇Launcher Icon
l  Foreground
指定圖示之圖案來源,Asset Studio提供三種方式,說明如下:
n  Image
Asset Studio預設是使用內建的ic_launcher.png檔做為圖示之圖片來源檔。點擊Image file:設定欄右側的「...」按鈕,即可指定使用其它圖片檔做為圖示圖案。

n  Clipart
使用內建圖庫做為圖示圖案來源。點擊Clipart:欄之「Choose...」按鈕,然後從內建圖庫清單中挑選圖案。

n  Text
使用文字字串內容做為圖示圖案來源,可由Text:欄設定文字字串,Font:」欄指定文字字型
£ Trim surrounding Blank Space
勾選此項,表示自動裁切圖案周圍的空白。
l  Additional Padding
設定,用來調整圖示圖案與四周之留白空間。
l  Foreground Scaling
圖案縮放方式,Crop表示以圖案中心為基準,裁切圖檔使寬度或高度符合圖示大小;Center表示縮放圖檔使其內容可以全部顯示在圖示中。
l  Shape
圖示外框形狀,None表示不加外框;Square表示加方框;Circle表示加圓框。
l  Background Color
Shape設定為SquareCircle時,Background Color表示圖示之底色。雙擊滑鼠左鍵或點擊滑鼠右鍵可開啟調色盤,從中挑選圖示底色。
l  Foreground Color
當使用Clipart做為圖示之圖案來源時,Foreground Color表示圖案顏色;而當使用Text做為圖示之圖案來源時,Foreground Color表示文字圖案顏色。雙擊滑鼠左鍵或點擊滑鼠右鍵可開啟調色盤,從中挑選圖示顏色。

2014年6月1日 星期日

使用CocoonJS封裝Construct 2專案APK

1. 確認專案已設定Full screen in browser
  a.File/Export project…
  b.選取Mobile/CocoonJS
  c.專案會被壓縮為zip檔
2. 調用CocoonJS Cloud Compilation Service
  a.上傳Construct 2匯出的壓縮檔
  b.等待CocoonJS通知郵件
3. 下載CocoonJS轉換完成的壓縮檔

CocoonJS建構的壓縮檔中包括debug及unsigned release二種版本APK,前者以_debug_signed.apk結尾,後者以_release_unsigned.apk結尾。
unsigned release版本APK檔需要再使用keystore簽章後才可以發佈到Google Play
jarsigner -verbose -keystore your.keystore your_release.apk alias_name


教學投影片


2014年5月27日 星期二

使用XDK發佈Construct 2專案到Android手機


1. 安裝Intel XDK
下載:http://xdk-software.intel.com/
2. 註冊XDK用戶帳號
3. 匯出Construct 2專案
a. 確認專案已設定Full screen in browser
b. Construct2功能表File/Export project…,選取Mobile/Android
4. 使用XDK封裝步驟3匯出的Construct 2專案
a. Start with a Blank Project,指定專案名稱及儲存目錄
b. 將Construct 2匯出的資料夾複製到XDK專案www資料夾
c. 按下Build App Now按鈕,將Construct 2專案封裝成APK檔

教學投影片

2013年9月4日 星期三

Android App設計 - 從網頁開啟App

首先為App之AndroidManifest.xml加入一個App專屬的<intent-filter>,例如
    <activity
        android:name="MyappMain"
        android:label="@string/app_name"
        android:noHistory="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <data android:scheme="nkut.edu.sswuApp" android:host="nkut" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
        </intent-filter>
    </activity>

在此設定的android:scheme屬性值就是HTML網頁中連結App的通關密語,只要在網頁中使用超連結到"nkut.edu.sswuApp"即可,例如:

<html>
    <head>
        <title>launch apk from browser</title>
        <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8">
    </head>
    <body>
        <p>
        <a href = "intent://nkut#Intent;scheme=nkut.edu.sswuApp;end">點我開啟APP</a></p>
    </body>
</html>

2013年8月23日 星期五

Android App設計: 抑止Back鍵結束Activity

Android手機預設按Back返回鍵就會結束目前Activity,如果不希望使用者透過Back返回鍵結束程式,可Override onBackPressed()方法,不讓它執行預設的super.onBackPressed();即可

@Override
public void onBackPressed() {
// 抑止使用者按Back鍵結束程式
}

Android App設計: 抑止Activity被放入Acticity Stack

預設使用Intent啟動另一個Activty時,原先的Activty會被自動放置到Activity Stack,當Callee Activity結束時,就會自動返回原先的Activty。

如果不想要Activity被放入Acticity Stack,可在startActivity(intent);指令後使用finish()指令
  
  Intent intent = new Intent();
  intent.setClass(MainActivity.this, CalleeActivity.class);
  startActivity(intent);        
  finish();

或在AndroidManifest.xml,將Acticity之android:noHistory屬性設定為true。
  
  <activity
      android:name="SchoolcisMain"
      android:label="@string/app_name"
      android:noHistory="true" >

2013年6月14日 星期五

Android程式設計 - HTTP資料傳遞(2)使用POST

假設伺服端httppost.php網頁如下,:
<?php
//宣告使用utf-8編碼
header("Content-Type:text/html; charset=utf-8");
$user=$_POST['login_user'];
$pass=$_POST['login_pw'];
echo "login_user=".$user.";login_pw=".$pass;
?>

我們可以先使用以下表單來驗證網頁功能
<html>
<body>
測試POST資料傳送:
<form method="POST" action="http://163.22.249.40/myPHP/httppost.php">
帳號:
<input type="text" name="login_user" size="20"value="sswu" /><br />
密碼:
<input type="text" name="login_pw" size="20" value="1234" /><br />
<input type="submit" name="btnSend" value="送出" /><br />
</form>
</body>
</html>

HTTP POST與HTTP GET主要差異在於參數資料傳遞方式,使用POST方式時必須使用setEntity()設定POST參數,程式如下:

String Url = "http://my_webserver/httppost.php";
//設定POST參數
List postData = new ArrayList();
postData.add(new BasicNameValuePair("login_user", "sswu"));
postData.add(new BasicNameValuePair("login_pw", "0123"));
String result = httpGET(Url, postData);
if (result == null) {
//顯示錯誤訊息
}
        ...

    /**
     * Issue a POST request to the server.
     * @param url POST address.
     * @param params request parameters.
     */
    private String httpPOST(String url, List params){ 
        HttpPost post = new HttpPost(url);
        try {
            //送出HTTP request
            post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
            //取得HTTP response
            HttpResponse httpResponse = new DefaultHttpClient().execute(post);
            //檢查狀態碼,200表示OK
            if (httpResponse.getStatusLine().getStatusCode()==200){
                //取出回應字串
                String strResult = EntityUtils.toString(httpResponse.getEntity());
                return strResult;
            }
        catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

Android程式設計 - HTTP資料傳遞(1)使用GET

假設伺服端httpget.php網頁如下,:
<?php
//宣告使用utf-8編碼
header("Content-Type:text/html; charset=utf-8");
$user=$_GET['login_user'];
$pass=$_GET['login_pw'];
echo "login_user=".$user.";login_pw=".$pass;
?>

我們可以先使用以下表單來驗證網頁功能
<html>
<body>
測試GET資料傳送:
<form method="GET" action="http://163.22.249.40/myPHP/httpget.php">
帳號:
<input type="text" name="login_user" size="20"value="sswu" /><br />
密碼:
<input type="text" name="login_pw" size="20" value="1234" /><br />
<input type="submit" name="btnSend" value="送出" /><br />
</form>
</body>
</html>

HTTP GET是將參數附加在URL之後,例如:http://my_webserver/httpget.php?login_user=sswu&login_pw=1234,Android中可使用HttpGet 物件進行HTTP GET資料傳遞,程式如下:

String Url = "http://my_webserver/httpget.php";
//設定GET參數
List getData = new ArrayList();
getData.add(new BasicNameValuePair("login_user", "sswu"));
getData.add(new BasicNameValuePair("login_pw", "0123"));
String result = httpGET(Url, getData);
if (result == null) {
//顯示錯誤訊息
}
        ...

    /**
     * Issue a GET request to the server.
     * @param url GET address.
     * @param params request parameters.
     */
    private String httpGET(String url, List params){
        //組合成http get格式
        StringBuilder sb = new StringBuilder();
        sb.append(url).append("?");
        for (NameValuePair nvp : params) {
            try{
                sb.append(nvp.getName()).append("=").append(URLEncoder.encode(nvp.getValue(), "utf-8"));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            sb.append('&');
        }
        sb.deleteCharAt(sb.length()-1);
        HttpGet get = new HttpGet(sb.toString());
        try {    
            //送出HTTP request並取得HTTP response
            HttpResponse httpResponse = new DefaultHttpClient().execute(get);
            //檢查狀態碼,200表示OK
            if (httpResponse.getStatusLine().getStatusCode()==200){
                //取出回應字串
                String strResult = EntityUtils.toString(httpResponse.getEntity());
                return strResult;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

2013年5月16日 星期四

Android程式設計 - 使用Fluid UI工具與用戶溝通

用戶溝通與需求訪談是系統開發初期最重要的事項,妥善運用Wireframe工具可大幅縮短溝通時程,降低功能認知落差,針對Apps開發,Fluid UI是一款方便實用的線上Wireframe & Prototype工具,可快速建構Android, iOS and Windows 8 apps趨型。
https://www.fluidui.com/editor/live/


2013年5月10日 星期五

Android程式設計 - Google Maps API v2在地圖上繪圖

程式中可在Google Map上繪製連續線、圓形及多邊形,且繪製的幾何圖形會自動隨地圖縮放調整比例。
GoogleMap.addPolyline()方法用來在地圖上描繪連續線段。
GoogleMap.addPolygon()方法用來在地圖上描繪多邊形。
GoogleMap.addCircle()方法用來在地圖上描繪圓形。
例如:

  m_map = ((SupportMapFragment)
      getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
  LatLng p1 = new LatLng(23.95616, 120.68509);
  LatLng p2 = new LatLng(23.95666, 120.68585);
  LatLng p3 = new LatLng(23.95836, 120.68732);
     m_map.addPolyline(new PolylineOptions().
       add(p1, p2, p3).
       width(5).
       color(Color.LTGRAY).
       geodesic(true));
     m_map.addCircle(new CircleOptions().
       center(p1).
       radius(10).
       strokeWidth(5).
       strokeColor(Color.RED));
     m_map.addCircle(new CircleOptions().
       center(p2).
       radius(10).
       strokeWidth(5).
       strokeColor(Color.RED));
     m_map.addCircle(new CircleOptions().
       center(p3).
       radius(10).
       strokeWidth(5).
       strokeColor(Color.RED));



2013年5月9日 星期四

Android程式設計 - Google Maps API v2自訂地標訊息視窗

預設的地標訊息titlesnippet都只能顯示單行文字,當文字訊息過長時,後面的部份就只顯示「」而看不到完整的文字內容。
要自訂地標訊息視窗樣式,首先必須為地標訊息視窗設計所需的版面配置,例如使用一個圖示與二個文字方塊做為地標訊息視窗版面。



接著為GoogleMap設計一個Adapter類別,在該類別的getInfoContents()方法中,將所要顯示的地標titlesnippet內容設定到自訂的地標訊息視窗版面元件中。
class MyInfoWindowAdapter implements InfoWindowAdapter {
  @Override
  public View getInfoContents(Marker marker) {
     // 依指定layout檔,建立地標訊息視窗View物件
     View infoWindow = getLayoutInflater().inflate(R.layout.my_infowindow, null);
     // 顯示地標title
     TextView title = ((TextView)infoWindow.findViewById(R.id.txtTitle));
     title.setText(marker.getTitle());
     // 顯示地標snippet
    TextView snippet = ((TextView)infoWindow.findViewById(R.id.txtSnippet));
     snippet.setText(marker.getSnippet());
     return infoWindow;      
  }
  ...
}
最後設定GoogleMap使用自訂的MyInfoWindowAdapter物件做為地標訊息視窗轉接器。
    m_map.setInfoWindowAdapter(new MyInfoWindowAdapter());