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

2014年10月7日 星期二

[ Android ] Add device driver to kernel

take a note!

===================================================

To cross compile your own driver in the arm architecture you have to follow some steps as mentioned below.
  1. Create a directory like my_drvr inside drivers(which is in the Linux source code) for your driver and put your driver (my_driver.c) file inside this directory. It will looks like /linux_source_code/drivers/my_drvr/my_driver.c
  2. Create one Makefile inside your driver directory (using vi any editor) and inside this put obj-$((CONFIG_MY_DRIVER) += my_driver.o and save this file. This will appears like /linux_source_code/drivers/my_drvr/Makefile
  3. Create one Kconfig file inside your driver directory (using vi any editor) and inside this put
    config MY_DRIVER
    tristate "my driver" //gives your driver description like vendor name etc.
    depends on ARM
    default y if ARM
    help
      my driver module.
  4. Save this file, this will appears like /linux_source_code/drivers/my_drvr/Kconfig
  5. Add both Makefile and Kconfig file in the Linux source drivers Makefile and Kconfig file which are at /linux_source_code/drivers/Makefile and /linux_source_code/drivers/Kconfig
  6. In the Makefile add below in last line
     obj-y    += my_drvr/ 
    or
     obj-$((CONFIG_MY_DRIVER)  += my_drvr/
  7. In Kconfig file add below in last line
    source "drivers/my_drvr/Kconfig"
  8. Finally have to add Kconfig file into architecture specific config file which will be at kernel_source/arch/arm/configs/--defconfig in this add below line in the last
    CONFIG_MY_DRIVER=y
Note:- Last step will differ according to your architecture, so that you have take care. Now you can compile your driver by using make command.

===================================================

2014年8月3日 星期日

[ Android ] : bluetooth HCI log ( >= android 4.3)


After android 4.2, the bluetooth stack was changed from bluez to bluedroid;
so... the log tool ( hci tools ) was abandoned.

But you can still get BT log by thess 3 steps :

1. enable BT HCI logger at "settings > developer" :

2. modify the log level you want trace :

a. the location of configure file at /etc/bluetooth/bt_stack.conf

b. then modify the file content:
============================================================
# Enable BtSnoop logging function
# valid value : true, false
BtSnoopLogOutput=false

# BtSnoop log output file
BtSnoopFileName=/sdcard/btsnoop_hci.log

# Enable trace level reconfiguration function
# Must be present before any TRC_ trace level settings
TraceConf=true

# Trace level configuration
#   BT_TRACE_LEVEL_NONE    0    ( No trace messages to be generated )
#   BT_TRACE_LEVEL_ERROR   1    ( Error condition trace messages )
#   BT_TRACE_LEVEL_WARNING 2    ( Warning condition trace messages )
#   BT_TRACE_LEVEL_API     3    ( API traces )
#   BT_TRACE_LEVEL_EVENT   4    ( Debug messages for events )
#   BT_TRACE_LEVEL_DEBUG   5    ( Full debug messages )
#   BT_TRACE_LEVEL_VERBOSE 6    ( Verbose messages ) - Currently supported for TRC_BTAPP only.
TRC_BTM=2
TRC_HCI=2
TRC_L2CAP=2
TRC_RFCOMM=2
TRC_OBEX=2
TRC_AVCT=2
TRC_AVDT=2
TRC_AVRC=2
TRC_AVDT_SCB=2
TRC_AVDT_CCB=2
TRC_A2D=2
TRC_SDP=2
TRC_GATT=2
============================================================
you should change BtSnoopLogOutput=false >> BtSnoopLogOutput=true
and change the log level you interest, like : TRC_L2CAP=2 >> TRC_L2CAP=5
notice that the output log file at /sdcard/btsnoop_hci.log

3. read your output log file by wireshark :




2014年3月12日 星期三

[ Android ] : enable settings page of your Aplication

You can easily add "Settings feature" to your android app, just following these 10 steps:
( Android 4.0 & 4.4 works fine )

1. You need create your android app project with eclipse first. (here sample project is "enableSettings")

2. right click your android project >> new >> others


3. select "Android Activity"

4. select "Settings Activity"

5. No need to change, next step.

6. This "settings feature" need dependency android lib, if you can't press "Next" button, just install it.

7. Now just start your app see if can run normally, UI should like this:

8. then add this code in your android MainActivity.java, after that you should be able to go to "SettingsActivity" page:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
       
        switch (item.getItemId()) {
       
        case R.id.action_settings:
            
            Intent i = new Intent(this, SettingsActivity.class);
            startActivityForResult(i, 0);

            break;

        default:
            break;
        }
        return true;
    }

9. You can see the template settings from android now, and there are check box for boolean variable, editable dialog for string variable, list dialog for int & string ...etc, you can easily use what you need.



10. Next step you need to do a little study into the "SettingsActivity.java" file to know how to use it; and "SharedPreferences" class to access/store your app's preference.





2014年1月19日 星期日

[ Android ] : 10MinNews, dedicated app for CNN 10

Update : 2020/02/21

App Name : 10MinNews

Newest version : 1.4

App Type : English Learning / News

Install : install page

Download apk:from google cloud

簡介 :
追蹤最近 60 天 CNN 10 的影片與簡稿;
可以邊看影片邊看簡稿比對學習,幫助你增加英文的聽讀能力。

Introduce :
Trace latest 60 videos & scripts of CNN 10.
You can watch video & script at same page / at same time.
Easily enhance your English reading & listening abilities.

主要功能包括 :
- 下載影片與簡稿到本地後可離線操作。
- 選取簡稿單字,翻譯並紀錄。
- 分享你的單字筆記。

Main Features include :
- You can download video & script to do offline learning.
- You can select a word to translate, to take a note.
- You can share your note.

Demo Pictures :






2013年8月12日 星期一

[ Android ] : Monkey test

example :

adb shell monkey -p com.package.name --throttle 100 -s 43686 -v 50000

-p           : package name
--throttle : interval between event
-s           : random seed
-v           : number of simulated event

others:
================================================================
usage: monkey [-p ALLOWED_PACKAGE [-p ALLOWED_PACKAGE] ...]
              [-c MAIN_CATEGORY [-c MAIN_CATEGORY] ...]
              [--ignore-crashes] [--ignore-timeouts]
              [--ignore-security-exceptions]
              [--monitor-native-crashes] [--ignore-native-crashes]
              [--kill-process-after-error] [--hprof]
              [--pct-touch PERCENT] [--pct-motion PERCENT]
              [--pct-trackball PERCENT] [--pct-syskeys PERCENT]
              [--pct-nav PERCENT] [--pct-majornav PERCENT]
              [--pct-appswitch PERCENT] [--pct-flip PERCENT]
              [--pct-anyevent PERCENT] [--pct-pinchzoom PERCENT]
              [--pkg-blacklist-file PACKAGE_BLACKLIST_FILE]
              [--pkg-whitelist-file PACKAGE_WHITELIST_FILE]
              [--wait-dbg] [--dbg-no-events]
              [--setup scriptfile] [-f scriptfile [-f scriptfile] ...]
              [--port port]
              [-s SEED] [-v [-v] ...]
              [--throttle MILLISEC] [--randomize-throttle]
              [--profile-wait MILLISEC]
              [--device-sleep-time MILLISEC]
              [--randomize-script]
              [--script-log]
              [--bugreport]
              [--periodic-bugreport]
              COUNT
================================================================

2013年8月2日 星期五

[ Android ] : save an array to SharedPreferences


save array to SharedPreferences :

public boolean saveArray(String[] array, String arrayName, Context mContext) {  
    SharedPreferences prefs = mContext.getSharedPreferences("preferencename", 0); 
    SharedPreferences.Editor editor = prefs.edit(); 
    editor.putInt(arrayName +"_size", array.length); 
    for(int i=0;i<array.length;i++) 
        editor.putString(arrayName + "_" + i, array[i]); 
    return editor.commit(); 
}


load array from SharedPreferences :

public String[] loadArray(String arrayName, Context mContext) { 
    SharedPreferences prefs = mContext.getSharedPreferences("preferencename", 0); 
    int size = prefs.getInt(arrayName + "_size", 0); 
    String array[] = new String[size]; 
    for(int i=0;i<size;i++) 
        array[i] = prefs.getString(arrayName + "_" + i, null); 
    return array; 

}  

[ Java ] : Read text file to string

source code :

    public String readFileAsString(String filePath) throws java.io.IOException
    {
        BufferedReader reader = new BufferedReader(new FileReader(filePath));
        String line, results = "";
        while( ( line = reader.readLine() ) != null)
        {
            results += line;
        }
        reader.close();
        return results;

    }

[ Android ] : Static Way to get Context



public class MyApplication extends Application{

    private static Context context;

    public void onCreate(){
        super.onCreate();
        MyApplication.context = getApplicationContext();
    }

    public static Context getAppContext() {
        return MyApplication.context;
    }

}

then just call  MyApplication.getAppContext(); to get context


[ Java ] : check if file exist

code:

    public boolean isFileExist(String path) {
        File file = new File(path);
        if (!file.exists()) {
            return false;
        } else {
            return true;
        }

    }

[ Android ] : Download a file & showing the progress


There are several ways to achieve this goal,

One simplest way I tried & succeed below is to use DownloadManager class (GingerBread and newer only):

1. check if download manager is available:

    /**
     * @param context used to check the device version and DownloadManager                     information
     * @return true if the download manager is available
     */
    public static boolean isDownloadManagerAvailable(Context context) {
        try {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setClassName("com.android.providers.downloads.ui",                                "com.android.providers.downloads.ui.DownloadList");
            List<ResolveInfo> list =                                                             context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
            return list.size() > 0;
        } catch (Exception e) {
            return false;
        }
    }

2. if step 1 checked OK, download from some URL:

String url = "some url path";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("to /sdcard/download");
request.setTitle("some string");
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    request.allowScanningByMediaScanner();
    request.setNotificationVisibility(DownloadManager.Request.
                          VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "some string");

// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);