2013年4月14日 星期日

Android 用 adb shell啟動 Activity

在app中intent 可以透過Action或是Activity Name來啟動新的Activity
用adb shell 也同樣可以做到

1. 用Action啟動 activity

adb shell am start -a android.intent.action.MAIN

可以再加上category


adb shell am start -a android.intent.action.MAIN -c android.intent.category.HOME



2. 用activity name 啟動 activity
注意前面要加上package name
格式:am start -n package name / activity name  )

am start -n com.demo.browser/com.demo.browser.BrowserActivity

2013年3月9日 星期六

iphone 同步 google 聯絡人

iphone 同步 google 聯絡人
版本ios6

1.選擇桌面的設定



























2.選擇 郵件、聯絡資訊、行事曆


























3. 新增帳號


4. 選擇 “其他”


5.新增 CardDav 帳號

6. 伺服器輸入 google.com  使用者名稱輸入完整的郵件信箱, 密碼
7. 按下一步 驗證後完成同步~

2012年11月5日 星期一

Android GPS 如何停止搜尋狀態

假設LocationManager 用的是系統的service
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

mLocationManager .requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 100, MyLocation.this);

當App 關閉之後,會發現GPS還會繼續搜尋 導致手機耗電
這是因為這段code把 LocationListener 綁到了service中

所以要記得在關閉App後 解除綁定

protected void onDestroy() {
super.onDestroy();
locationManager.removeUpdates(MyLocation.this);
}

2012年9月9日 星期日

如何用Excel建立 直條圖(長條圖) 與 折線圖 合併圖表


1.插入折線圖








2.對圖表按右鍵 -> 選取資料














3.按住ctrl 選取要做成圖表數據 (這邊選Acc.Volume Acc. Revenue Acc. Expenditure)












4.點擊水平下的編輯 -> 選擇座標軸橫軸標籤範圍


5.對想要換成長條圖的折線 點擊右鍵 -> 變更數列圖表類型






6.選擇長條圖























7.因為使用的單位不同  所以要新增第二個縱軸
   對直條圖點擊右鍵 -> 資料數列格式













8.選擇副座標軸 -> 確定


9. 完成!












excel 合併圖表, excel 圖表合併, 長條圖和折線圖結合,  excel 圖表合併, excel圖表

2012年5月17日 星期四

數據存儲 in Android - 使用 SharedPreferences

目的: 簡單和快速的儲存數據 使用上感覺像簡易版wp7的IsolatedStorage

範例:


2012年5月15日 星期二

Intent and Intent Filter in Android

內容涵蓋:
1.在App中開啟另一個App
2.了解Intent-Filter的使用

參考:
http://developer.android.com/reference/android/content/Intent.html
http://developer.android.com/guide/topics/intents/intents-filters.html


首先從Intent說起

先看一下官方文檔:


  • Explicit Intents have specified a component (via setComponent(ComponentName) or setClass(Context, Class)), which provides the exact class to be run. Often these will not include any other information, simply being a way for an application to launch various internal activities it has as the user interacts with the application.
  • Implicit Intents have not specified a component; instead, they must include enough information for the system to determine which of the available components is best to run for that intent.



  • 可以看到Intent分為兩個種類
    一種為  Explicit Intents
    另一種為  Implicit Intents

    查一下英文字典:
    Explicit  adj. 明顯的
    Implicit  adj. 暗示的

    從文檔可看出 Explicit Intent 使用方式很明確 就是指定 component 讓系統去調用
    而 Implicit Intent就是提供"資訊", 讓系統決定去調用哪個component


    本文要講的重點是第二種: Implicit Intent

    而要了解Implicit Intent必須先了解 Intent-Filter
     Intent-Filter由三個元素組成
    1.action
    2.category
    3.data
    而從Filter本身的含意 : 過濾,篩選
    可以判斷 Intent-Filter可以指定上列三種元素的屬性
    進而讓符合條件的Intent通過, 進而執行該Activity or Service or..
    因此可以得知 Implicit Intent 要提供的資訊就是上面這三種


    如果寫過打電話的功能,  一定看過以下代碼



    Intent _Intent = new Intent();
    _Intent.setAction(Intent.ACTION_DIAL);
    _Intent.setData(Uri.parse("tel:0123456789"));
    startActivity(_Intent);



    而其中的 Intent.ACTION_DIAL   中就是Android中撥號的Activity中所指定的Action


    那如何使用自己的Action呢?
    以下為代碼


    <activity
         android:name=".intent.IntentDemoActivity"
         android:label="@string/app_name" >
         <intent-filter>
              <action android:name="maca.demo.GOTO_INTENT" />
              <category android:name="android.intent.category.DEFAULT" />
         </intent-filter>
    </activity>


    指定action為"maca.demo.GOTO_INTEN"
    而如何調用就和之前一樣


    Intent _Intent = new Intent();
    _Intent.setAction("maca.demo.GOTO_INTENT");
    startActivity(_Intent);


    而category和data也就是同樣的原理 這裡僅附上代碼

    xml:

    <intent-filter>
        <action android:name="maca.demo.GOTO_INTENT" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="maca.demo.category.INTENT" />
        <data android:scheme="hello" android:mimeType="text/plain"></data>
    </intent-filter>



    java:


    Intent _Intent = new Intent();
    _Intent.setAction("maca.demo.GOTO_INTENT");
    _Intent.addCategory("maca.demo.category.INTENT");
    _Intent.setDataAndType(Uri.parse("hello://nihowma"), "text/plain");
    startActivity(_Intent);




    2012年5月12日 星期六

    Random String in Python


    '''
    Created on 2012-5-13

    @author: cnp
    '''

    import string
    import random


    def random_string(size=6, chars=string.ascii_letters + string.digits):
        return ''.join(random.choice(chars) for x in xrange(size))


    print random_string()



    output:

    bXwN6t