Posts Tagged ‘Android’

[Android] Simple repeat timer count

Tuesday, November 15th, 2011

I practiced to make timer base app.

When start button is pushed, it starts to count up and shows counted value in the label.
When stop button is pushed, it stops to count up.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >

        android:text="@string/hello" />

        android:layout_height="wrap_content" >

            android:text="Start" />

            android:text="Stop" />



package com.mytimer;

import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TimerSampleActivity extends Activity implements View.OnClickListener{
    private final String TAG = "TimerSample";  
	private Button mStartButton;
	private Button mStopButton;
	public int currentTime;
	private Handler _myHandler;
	private TextView mCurrentTimeLabel;
	private Runnable _myTask;
    public void onCreate(Bundle savedInstanceState) {
        currentTime = 0;
        mStartButton = (Button)findViewById(;
        mStopButton = (Button)findViewById(;
        mCurrentTimeLabel = (TextView)findViewById(;

	public void onClick(View v) {
		if(v.getId() =={
			Log.d(TAG, "start");
			_myTask = new MyTimerTask();
			_myHandler = new Handler();
			_myHandler.postDelayed(_myTask, 100);
		else if(v.getId() =={
			Log.d(TAG, "stop");
	private void cancelTimer()
		if(_myHandler != null){
	private class MyTimerTask implements Runnable
		public void run() {
			_myHandler.postDelayed(this, 100);

Below page is original source code page.
Updating the UI from a Timer

[Android] How to access media data in assets and res/raw folder

Monday, November 14th, 2011

To make custom media player, I tried to use MediaPlayer.
But when I set datasource, it could not work well.

I placed video files in assets/ or res/raw.
I didn’t know how to access.

I googled.
Then I found the solution.

If you placed in assets/video_file.mp4

_player = new MediaPlayer();
AssetFileDescriptor afd = getAssets().openFd("video_file.mp4");
_player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
_player.setDisplay(_holder); //_holder is SurfaceHolder of SurfaceView

Or if you placed in res/raw/video_file.mp4

_player = new MediaPlayer();
 String fileName = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
_player.setDataSource(this, Uri.parse(fileName));
_player.setDisplay(_holder); //_holder is SurfaceHolder of SurfaceView

These pages have some very useful information.

Discovering Android – Embedding Video in an Android Application
Play audio file from the assets directory

[Android] how to make display to fullscreen

Monday, November 14th, 2011

There are several way to make display to fullscreen.

method 1)
this method’s point is placing requestWindowFeature between onCreate and setContentView.

    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE); // to fullscreen

method 2)
add theme property application or activity xml tag in AndroidManifest.xml.


see this page

[Android] Honeycomb Android 3 system bar height is 48px

Monday, November 14th, 2011

Honeycomb Android 3 system bar height is 48px.

If your device display size is WXGA (1280 x 800), your content height is 752px.

[Android] How to make Sony Tablet S been able to develop on mac.

Monday, November 14th, 2011

I can’t connect to Sony Tablet S from my mac.
I searched, and found how to solve.

This page gives me very useful information.
[Q] Sony Tablet S ADB support

It says

you need to cd to your .android folder (on a mac, this is ~/.android) and then type

echo 0x054c > adb_usb.ini

Where 0x054c is the vendor id for Sony (I got that by looking at the attached evices in the 'About this mac' preferences)

I found the file named adb_usb.ini in below location.


Then, I opened the file with text editor.
and added the sentence.


and restart the adb server. In terminal app

./adb kill-server
./adb start-server

Then adb could recognize my tablet.

You can confirm usb vender id from this.
About This Mac > More Info > System Report > Hardware | USB > USB Device Tree > Vendor ID:

[Android] Failed to install app, timeout

Tuesday, October 11th, 2011

I got an error on debugging.
When I debugging, I can’t install my app.

The article on this link is the same error.
Android error: Failed to install *.apk on device *: timeout

And I could see how to fix it.

First, change the time of time out longer.

Preference > Android > DDMS
ADB connection time out (ms):
I changed default 5000 to 10000.

Second, reboot adb.

On the terminal app, I typed this code.

adb kill-server
adb start-server

I could fix it.