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

2022年2月8日 星期二

Android的自動重撥程式,訂票必備工具(推)

2百萬下載!自動重撥Android APP,支援Android 5.0 to 14


***最新功能,支援雙卡撥打 ***


教學影片:

1.如何開始/停止自動撥號

https://youtu.be/cDNy4c-x0iw

2.如何切換到2張SIM卡

https://youtu.be/jabUJxbmfjw

3.顯示停止掛斷定時器

https://youtu.be/IhbaK49JHhA


●支援版本

Android 5 to 14

使用情境:

-搶車票、旅遊季搶票必備

-掛號必備

-奪命連環摳必備

 

主要功能特色:

-支援雙卡手機撥打

-自動掛斷

-自動重撥

-擴音開啟功能

-振動提示

-聲音提示

-支援分機撥打

 

使用方法:

1)設定自動切斷通話時間:可設定0-60(預設為10)

2)設定重撥間隔:可設定0-60(預設為5)

3)切換SIM(雙卡機使用)

4)手動輸入號碼或點選右邊圖案進入聯絡人

5)"綠色"撥號鍵,來開始自動重撥

6)"紅色"停止鍵,來結束自動重撥

 

 

影片教學: 

APP下載:  自動重撥Android APP

 


2021年10月11日 星期一

Android auto redial / call timer (Android App)

2,000,000 Download!Call timer, auto redial and hang up call(Android 5.0 to 11)

 

Support Dual SIM Phone(2 SIMs card phone)

 

●Support version

Android 5.0 to 14


Tutorial video:

1.how to Start/Stop auto dial

https://youtu.be/cDNy4c-x0iw

2.how to switch to 2 SIMs

https://youtu.be/jabUJxbmfjw

3.Show stop hang up timer

https://youtu.be/IhbaK49JHhA


●Description:

-Auto redial phone number again and again in a very easy way.

-Make your phone automatically hang up with the timer you setting.

 

 ●The main features includes:

-Support Dual SIM Phone(2 SIMs card phone)

-Auto hang up

-Auto redial

-Fast redial

-Speaker on/off

-Vibration alert

-Sound alert

-dial extension number

 

 ●Unique features:

-When the number you dialed entering voice mail, for this case, you could enable "Show hang up timer" from Others/Setting/Advanced,then enable the permission.

And set a shorter end call time(suggest 10-15 secs) and enable speaker on, then when you hear answer by person, click the "cancel the timer" button to stop to auto hang up the call 

 

 ●How to use this application:

1)drag first bar to set hang up time

2)drag second bar to set redial interval

3)Switch your sim card(for 2 SIMs phone)

4)Enter the phone number or enter contact with click icon

5)press green button to start auto redial

6)press red button to stop auto redial

 

Guide Video: 

Download Android App: Auto Redial | call timer

 


2014年12月7日 星期日

Git note

Git指令教學(reset)
  • 檔案改爛了怎麼辦 
         -commit之前改爛了,恢復到修改前
           a. git checkout [file_name]
           b. git reset --hard
         -commit之後改悔了,恢復到前一版的commit
           a. git reset --hard HEAD^

2014年7月26日 星期六

新版AdMob 更新廣告單元編號 詳細步驟

Step1. 下載 Google Mobile Ads SDK  
進入Eclipse, 然後點選上面的Window -> Android SDK Manager , 再安裝Tools裡的
- Anddroid SDK Tools
- Android SDK Platform-tools
- Android SDK Build-tools



Step2. 載入 Google Play 服務程式庫專案
在上個步驟更新完後, 會多出一個資料夾,在<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/,把這個project,載入到Eclipse



Step3. 將我們的專案跟Google Play服務程式庫作連結

a. 在 Eclipse 中的應用程式專案上按一下滑鼠右鍵,並選取 [Properties]。


b. 選取 [Android],然後按一下 [Add...]。找出 google-play-services_lib 專案,然後選取 [OK] 來新增 Google Play 服務程式庫



Step4. 加入meta-data,如下面粗體字

 Step5.修改AndroidManifest.xml
 a.宣告 com.google.android.gms.ads.AdActivity,加入下面二行
 <activity android:name="com.google.android.gms.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>


b.設定網路權限,加入下列二行
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step6.在Activity裡加入adView程式 

Layout的main.xml如下


補充: 程式裡有一行MY_AD_UNIT_ID(也就是廣告單元編號),
要從AdMob 頁面的 [營利] -> [所有應用程式] -> [相關應用程式] 尋找廣告單元編號,
如下面紅框框


參考網站 : https://developers.google.com/mobile-ads-sdk/download

2014年6月3日 星期二

2013年8月29日 星期四

WIN遙控器

環境設定
(如您的版本是1.2,請先更新至2.0以上版本,然後重新下載第2步的電腦端程式)

1 安裝JAVA執行程式,請至下面連結下載
Download

2 下載電腦端程式WINRemoteService_1.0.rar,然後解壓縮,會看到有三個檔案(winremote_1.0_x64, winremote_1.0_x86, WINRemoteService_1.0, 前二者為32位元及64位元的程式庫,第三個就是執行檔)
Download

3 藍芽配對,先點選右上角案鈕,然後選擇"是"


進入控制台\硬體和音效\新增Bluetooth裝置,此時會電腦已找到您的手機(我的是GT-I9300),
然後點選按下一步


看到配對碼後一樣按下一步


在上個步驟後,手機端會出現對畫框如下,按下確定,即完成配對設定,

 ****上述這些設定只需做一次即可****


=========================================================
如何使用


1.點擊電腦端的WINRemoteService_1.0,來開啟服務
(少數的使用者會看到WINRemoteService_1.0變成RAR, 如果是的話,請點選此檔案,及按滑鼠右鍵,然後選"開啟檔案",最後選擇"JAVA(TM) platform SE binary)




2.點選右上角的按鈕,然後點選裝置名稱(KANZO-AIR是我的電腦名稱)


3.連接成功,可開始遙控嘍



=====================================================================
下載WIN遙控器連結:
http://powerpoint-remote844843.android.informer.com/1.2/


如有任何設定或操作上的問題,請留這或寫信給我

WIN remote control

Set up environment
(If your version is 1.2, please upgrade to 2.0 or newer)

1 Install Java program, download link below
Download

2 Download WINRemoteService_1.0.rar to your computer and unzip it, there'll be 3 files there(winremote_1.0_x64, winremote_1.0_x86, WINRemoteService_1.0, first two files are libraries for 32/64bit, the last file is execute file for lunching service)
Download

3.Pair Bluetooth device between computer and your android phone.


Enter Control Panel -> Hardware and Sound -> Add a Bluetooth device, then computer will
find your android phone(GT-I9300 is my phone type), click it and press "next"

Press "Next" key to pair your phone


After last step, your phone will auto show the dialog box below, just click "OK" to finish pair.
All of these steps above only do one time.



============================================================
Start to Use

1.double Click WINRemoteService_1.0  to lunch service.
(rarely users see the WINRemoteService_1.0 becoming .rar extension file,
 please click the file with mouse right button, choose "open with", then choose "JAVA(TM) platform SE binary)

2. Click the right-top button to connect to computer.(KANZO-AIR is my computer name)


3.If connection is successful, it will show as following.



============================================================
download WIN remote control from:
http://powerpoint-remote844843.android.informer.com/1.2/


If there're any problem about setting or use, please leave message here or mail me.

2013年8月4日 星期日

[Android] 如何監測長按結束 (Detect End of Long Press)

這個範例,我們來看看如何監看按壓按鈕的三個狀態
(This example will show you how to monitor click, long press and release button status)
1)點擊(click)
2)長按(long press)
3)放開(release)

File : MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class MainActivity extends Activity {

 boolean isBtnLongPressed = false;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  Button btn = (Button) findViewById(R.id.button1);

  btn.setOnLongClickListener(new HoldListener());
  btn.setOnTouchListener(new touchListener());
  btn.setOnClickListener(new clickListener());
 }

 //監聽點擊(detect click)
 private class clickListener implements OnClickListener {

  @Override
  public void onClick(View view) {
   Log.e("log", "click button");
  }
 }

 //監聽長按(detect long press)
 private class HoldListener implements OnLongClickListener {

  @Override
  public boolean onLongClick(View pView) {
   // Do something when your hold starts here.
   isBtnLongPressed = true;
   Log.e("log", "long press button");
   return true;
  }

 }

 //監聽放開按鈕(detect release button)
 private class touchListener implements OnTouchListener {

  @Override
  public boolean onTouch(View pView, MotionEvent pEvent) {
   
   if (pEvent.getAction() == MotionEvent.ACTION_UP) {
    
    if (isBtnLongPressed) {
     // Do something when the button is released.
     isBtnLongPressed = false;
     Log.e("log", "release");
    }
   }
   return false;
  }
 }

}


2013年8月3日 星期六

[Android] How to add a Dropdown item on the action bar

Action Bar是android 3.0提供的一個功能,像下圖這樣
(The Action Bar  APIs were first added in Android 3.0 as following picture)




這個範例將教大家,如何在Action bar上加入下拉選單
(This example will teach you how to add a dropdown item on action bar)


File : MainActivity.java
import java.util.ArrayList;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.OnNavigationListener;
import android.util.Log;
import android.widget.ArrayAdapter;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  final ActionBar actionBar = getActionBar();
  actionBar.setDisplayShowTitleEnabled(false);
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

  ArrayList itemList = new ArrayList();
  itemList.add("WMP");
  itemList.add("iTunes");
  itemList.add("Winamp");

  ArrayAdapter adapt = new ArrayAdapter(this,
    android.R.layout.simple_list_item_1, android.R.id.text1,
    itemList);
  actionBar.setListNavigationCallbacks(adapt, new DropDownListenser());
 }

 class DropDownListenser implements OnNavigationListener {

  public boolean onNavigationItemSelected(int itemPosition, long itemId) {
   if (itemPosition == 0) // windows media player
   {
    Log.e("log", "you choose WMP");
   }

   if (itemPosition == 1) // iTunes
   {
    Log.e("log", "you choose iTunes");
   }
   if (itemPosition == 2) // Winamp
   {
    Log.e("log", "you choose Winamp");
   }

   return true;

  }
 }

}

2013年7月31日 星期三

[Android] RelativeLayout範例介紹

在Android裡,RelativeLayout是一個最彈性的的Layout,
主要是利用上、下、左、右(above, below, left and right)來排列component的位置,
以我們這個例子來說,button2在button1的下面,button3在button2的右下方,button4在button3的右下方

File : res/layout/main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="Button1" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:text="Button2" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button2"
        android:layout_toRightOf="@+id/button2"
        android:text="Button3" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button3"
        android:layout_toRightOf="@+id/button3"
        android:text="Button4" />

</RelativeLayout>
結果:

[Android] TableLayout 範例介紹

在這個例子,我們來看如何用TableLayout來排列textView和button,
及如何使用“android:layout_span”將button寬度延伸成2欄位(column),
及使用“android:layout_column”來將按鈕放到特定的欄位。

File : res/layout/main.xml 
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
 
    <!-- 2個欄位 -->
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >
 
        <TextView
            android:id="@+id/textView1"
            android:text="第 1 欄"
            android:textAppearance="?android:attr/textAppearanceLarge" />
 
        <Button
            android:id="@+id/button1"
            android:text="第 2 欄" />
    </TableRow>
 
    <!-- 將按鈕延伸至2個欄位寬  -->
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >
 
         <Button
            android:id="@+id/button2"
            android:layout_span="2"
            android:text="第 1 和 2 欄" />
         
       
    </TableRow>
 
 
    <!-- 3個欄位 -->
    <TableRow
        android:id="@+id/tableRow3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >
 
        <TextView
            android:id="@+id/textView2"
            android:text="第 1 欄"
            android:textAppearance="?android:attr/textAppearanceLarge" />
 
        <Button
            android:id="@+id/button2"
            android:text="第 2 欄" />
 
        <Button
            android:id="@+id/button3"
            android:text="第 3 欄" />
    </TableRow>
 
    <!-- 利用layout_columnundefinedbase is 0),將按鈕放在第2欄 -->
    <TableRow
        android:id="@+id/tableRow4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >
 
        <Button
            android:id="@+id/button4"
            android:layout_column="1"
            android:text="第 2 欄" />
    </TableRow>
 
    <!-- 利用layout_columnundefinedbase is 0),將按鈕放在第3欄 -->
    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dip" >
 
        <Button
            android:id="@+id/button5"
            android:layout_column="2"
            android:text="第  3 欄" />
    </TableRow>
 
</TableLayout>

結果:



















延伸閱讀: [Android] RelativeLayout範例介紹

2013年7月21日 星期日

[Android] LinearLayout 範例介紹

LinearLayout是一個很常用的Layout,
主用是用orientation屬性來把component(如button)做垂直及水平的排列,
另外,帶有權重(weight)的component將會填滿剩餘的空間

我們來舉個例子,來看看如何把component做垂直及水平的排列,及weight如何使用

1. LinearLayout – 水平(Horizontal)
打開res/layout/main.xml,加入 android:orientation="horizontal",然後增加3個按鈕,
在這個例子中,我們將權重設在button3,所以它將會填滿剩餘的空間

res/layout/main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2" />
 
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3" 
        android:layout_weight="1"/>
 
</LinearLayout>
結果:



2. LinearLayout – 垂直(Vertical)
我們把orientation改成“Vertical

res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button1" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button2" />
 
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3" 
        android:layout_weight="1"/>
 
</LinearLayout>
結果:

[Android] 解決問題Your project contains errors,please fix them before running your application.

今天開啟eclipse要使用時,發現無法編譯,只出現Your project contains errors,please fix them before running your application.









 檢查所有程式,也找不到任何錯誤,只有project name上出現一個紅色叉叉,
 一般這個問題,可能是無法讀取R.class,我會先刪除gen\R.java檔,然後refresh
 然後Project>clean整個project,最後重新編譯一次。
 但這次這個方法沒用,哈























最後google發現是Debug認證已經過期,解決方法很簡單,
進入windows>Preferences>Android->Build,找到debug.keystore的路徑,刪除就可以了,
系統會在自己產生一個

2013年7月7日 星期日

[Android] adb logcat使用方法

● Logcat是一個即時觀看系統訊息(system messages)的工具,一般會利用ADB(android debug bridge)來啟動,如果是用eclipse開發,就在windows\ShowView裡,選LogCat,就可以打開了。

這裡我們利用ADB來作示範,在裝完android SDK後,裡面就會包含了ADB,
以Windows為例,adb路徑會在android-sdks\platform-tools\adb.exe,所以在開啟terminal後,要先切到這個路徑下。
而Linux,裝好SDK,開啟terminal就可以用了。

使用之前裝置端要先開啟USB偵錯模式,路徑如下,設定>開發人員選項>USB偵錯
然後在電腦端輸入
$ adb devices
會得到下面結果,表示已和裝置端連接成功



● 下列是Log class提供了幾個列印message到logcat的方法
v(String, String) (verbose)
d(String, String) (debug)
i(String, String) (information)
w(String, String) (warning)
e(String, String) (error)

一般在開發程式時,會在每個function的的第一行加上log,方便日後trace code
像下面這樣
Log.i("MyActivity", "test"); //log.i裡的i是指(information)
LogCat就會輸出log成這樣
I/MyActivity( 1555): test


● 如何輸出LOG呢
$ adb logcat
但這種方法log太多了,會印出全部的log,包含verbose/debug/information/warning/error
所以我們需要用到下列的方法過濾出我們要的部分


● 過濾log(Filtering Log Output)
每一個Android的log都包含了標籤(tag),和優先權(priority)
例如,I/MyActivity( 1557): test //I是優先權,又分成了下列幾種;MyActivity就是標籤
Android優先權:
V — Verbose (最低優先權)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (最高優先權,S表示不會用印出任何LOG)
為什麼分成七級呢?看到例子三就明白了

知道了android log之後,要如何過濾呢?我們用下面幾個例子來學習學習
例子一
//如果只想印出這種寫法Log.i("MyActivity", "test")的log,則要這樣寫

$ adb logcat MyActivity:I *:S

//MyActivity:I是表示,印出MyActivity標籤及information優先權的log

//*:S 是指其它所有的log都silent,也就是都不印出來

例子二
//如果我們一次想看這2種logs,則該怎麼寫呢?

//Log.i("MyActivity", "test");

//Log.d("MyActivity2", "test2");

$ adb logcat MyActivity:I MyActivity2:D *:S

例子三
那如果這樣寫$ adb logcat *:W 會發生什麼事呢?

這樣就會印出所有log,且優先權在Warning以上的log,也就是Warning/Error/Fatal



● 延伸
一般我們在做phone的project時,就會常用到
$ adb logcat -v time -b radio
//-v time是指出時間,-b radio是指印出radio和telephony相關訊息


●更多參考資料:
http://developer.android.com/tools/debugging/debugging-log.html#startingLogcat

2013年6月27日 星期四

[Android] Intent用法

● 呼叫電話(call a dial screen)
這裡要注意的是,"tel:"是必要的,不然會有錯誤
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("tel:1234567890"));
        startActivity(intent);


● 直接撥打電話(make a phone call)
如果不想要顯示撥號畫面,想直接撥打電話,則需要使用ACTION_CALL
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:0123456789"));
        startActivity(intent);
因為有使用到ACTION_CALL,所以要在manifest加入權限
<uses-permission android:name="android.permission.CALL_PHONE" />


● 呼叫瀏覽器(Browser)
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("http://www.acer.com"));
        startActivity(intent);

加入搜尋字串
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_WEB_SEARCH);
        // 設定搜尋的字串
        intent.putExtra(SearchManager.QUERY, "acer");
        startActivity(intent);


● 呼叫相機(Camera)
        Intent intent = new Intent();
        intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1);
取得拍攝後的照片
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode != RESULT_OK) {
            // 無法得到正確結果時會跑到這裡
            return;
        }

        if (requestCode == 1) {
            // 這個bitmap是拍攝之照片的資料
            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            // 在LAYOUT拉一個ImageView,來顯示照片
            ImageView imageView = (ImageView) findViewById(R.id.image);
            imageView.setImageBitmap(bitmap);

        }
}


● 呼叫錄音機(Recorder)
        Intent intent = new Intent();
        intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
        startActivity(intent);


● 呼叫Market應用程式(call market application)
       Intent intent = new Intent(Intent.ACTION_VIEW);
       intent.setData(Uri.parse("market://details?id=comq.android.autoRedial"));
       startActivity(intent);


● 顯示聯絡人清單
    Intent intent  = new Intent(Intent.ACTION_VIEW, People.CONTENT_URI);  
    startActivity(intent );  
顯示第3筆聯絡人的詳細資料
Uri uriContact = ContentUris.withAppendedId(People.CONTENT_URI, 3); //3 是聯絡人ID  
Intent intent   = new Intent(Intent.ACTION_VIEW, uriContact );  
startActivity(intent   );


● 顯示地圖
Uri uri = Uri.parse("geo:25.718058,-100.279487");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
//其他geo的用法 
//geo:latitude,longitude <--上面例子是這個
//geo:latitude,longitude?z=zoom    
//geo:0,0?q=business+near+city  
//google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom 
//geo:0,0?q=my+street+address 
路徑規劃
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en"); 
Intent intent  = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent ); 


延伸閱讀: 傳送郵件(Send mail)

2013年6月24日 星期一

[Android] 傳送郵件(Send mail)

● 傳送郵件(Send mail)
      Intent intent = new Intent();
      intent.setAction(Intent.ACTION_SENDTO);
      intent.setData(Uri.parse("mailto:chenkanzo@gmail.com"));
      intent.putExtra(Intent.EXTRA_SUBJECT, "這裡是主旨。");
      intent.putExtra(Intent.EXTRA_TEXT, "這是本文內容。");
      startActivity(intent);

● 傳送附件(Send mail with enclosed file)
和傳送郵件不同的利用Intent.ACTION_SEND,
而附件檔案必須利用Uri型別指定。
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_SEND);
        String[] to = {"hoge@example.com"};
        intent.putExtra(Intent.EXTRA_EMAIL, to);
        intent.putExtra(Intent.EXTRA_SUBJECT, "這是主旨。");
        intent.putExtra(Intent.EXTRA_TEXT, "這是本文內容。");
        
        // 選擇一張圖片來加入附件
        // 取得的SD卡資料夾
        File sdcard = Environment.getExternalStorageDirectory();
        File file = new File(sdcard, "test.jpg");
        intent.putExtra(Intent.EXTRA_STREAM,
                        Uri.parse("file://"+ file.getAbsolutePath()));
        intent.setType("image/jpeg");
        //呼叫應用程式列表
        startActivity(Intent.createChooser(intent,"請選擇郵件應用程式,例如GMAIL"));

延伸閱讀 Intent大全

[Android] 判斷網路連線的狀況(ConnectivityManager)

● 要判斷網路連線狀態很簡單,
1.利用ConnectivityManager類別。
2.接著利用getSystemService方法,並指定引數CONNECTIVITY_SERVICE即可。
 ConnectivityManager cm;
 cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);   

● 呼叫getACtiveNetworkInfo方法來取得目前的網路資訊,
回傳值null則表示離線狀態。
NetworkInfo NetInfo = cm.getActiveNetworkInfo();

        if (NetInfo == null) {
            Toast.makeText(getApplicationContext(), "離線狀態", Toast.LENGTH_SHORT).show();
        } else {
            if (NetInfo.isConnected()) {
                Toast.makeText(getApplicationContext(), "連線", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "離線", Toast.LENGTH_SHORT).show();
            }
        }

● 使用ConnectivityManager,別忘了要加權限到manifest裡
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

2013年6月17日 星期一

[Android] 避免螢幕自動關閉(FLAG_KEEP_SCREEN_ON)

當我們一段時間沒有觸碰螢幕時,畫面就會自動關閉。
這對一些應用程式,例如影片播放、相機來說,畫面自動關掉就一整個糗了。

要讓螢幕不要自動關閉的方法,只要利用Window class裡的addFlag方法,
並指定FLAG_KEEP_SCREEN_ON,就可以達到目的了。
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }


如果要回復的話,則可利用clearFlag這個方法,清掉之前設定即可。
 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

2013年6月14日 星期五

[Android] WebView

●WebView一般是用來顯示URL,但也可以用來顯示本地端的HTML資料。
首先我們先制定一個test.html,並放到assets\資料夾下。

assets/test.html
<!DOCTYPE HTML>
<html>
<body>

<p>WebView</p>
<b>This is a test page</b> 
<p>Thanks</p>

</body>
</html>

資料夾存放路徑


●主程式中,我們會利用下列的路徑格式讀取assets裡的html
file:///android_asset/檔名
下面程式會在程式啟動後,使用WebView顯示assets目錄下的test.html
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.webkit.WebView;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  WebView webView = (WebView)findViewById(R.id.webView1);
  webView.loadUrl("file:///android_asset/test.html");
 }
}
這裡補充一點,假如您需要多國的版本,如test_eng.html或test_tw.html
則可以先在strings.xml裡做相對應的字串
<string name="url_to_load">file:///android_asset/test_eng.html</string>
然後在程式裡利用webView.loadUrl(getString(R.string.url_to_load));讀出來。

●在layout裡加入一個webView就完成啦
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

●最後在AndroidManifest.xml加入INTERNET存取的權限
   <uses-permission android:name="android.permission.INTERNET" />

●結果

2013年6月13日 星期四

[Android] Eclipse亂碼解決方法

剛get了一個source code,載入eclipse發現中文都變成亂碼,
google一下solution,在這裡記錄下來,順便分享。

其實很簡單只需將Text file encoding從MS950(繁體中文 MS Windows 作業系統的編碼),
改成UTF-8

設定路徑,從上方選單進入Window->Preferences ->General->Workspace->UTF-8
有圖有真相