RSS

Monthly Archives: March 2012

How Do I Install the Android Market on Android SDK

By Lê Hoàng

Although the Android SDK is useful for developers, it lacks one important feature–the Android Market. Following these intructions, you can install Android Market. This will allow you to download and test free applications or games with the latest Android 2.3 SDK.

 

1. Download and install Android SDK. After that, set up a new emulator. (You may want to learn how to set up an Android Emulator

2. Go to …….\android-sdk_r08-windows\android-sdk-windows\platforms\android-9\images (this is the default folder for SDK Platform Android 2.3, API 9, revision 1), copy system.img and paste it to C:\Users\Username\.android\avd\Emulator’s name.avd

3. Download three files: Vending.apkGoogleServicesFramework.apk and ADB.zip(unzip the file after downloaded). After that, put all these files into …….\android-sdk_r08-windows\android-sdk-windows\tools, we will need them later. (In Android 2.3 SDK, adb files have been removed so that’s why we need them. If you use Android 2.2 SDK, you may not need to download the file)

3. Press Winkey+R, type cmd and press Enter. In command prompt, change the directory to …….\android-sdk_r08-windows\android-sdk-windows\tools (I kept the default folder structure but it is recommended that you change it).

4. Type the following: emulator –avd tech-recipes –partition-size 100 and hit Enter(please replace tech-recipes with your emulator’s name). This command will launch your emulator. Please don’t try to launch it from SDK manager, otherwise, it won’t work.

5. Launch another command prompt window, switch to …….\android-sdk_r08-windows\android-sdk-windows\tools , type in: adb -s emulator-5554 shell and hitEnter

(Please make sure that the emulator is fully loaded, and replace 5554 with your emulator’s serial code which you can find at the top of emulator’s window.) After that, type mount and hit Enter again. You will see something like below, and look for the line: /dev/block/mtdblock0 /system yaffs2 ro 00.


6. Now, type in:  mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system and hit Enter. This will remount the /system in read-write mode. Because we will copy some files to /system/app later, we must set read-write permission to that directory. To do it, type the following: chmod 777 /system/app , hit Enter. After that, you need to exit. Type exit, hit Enter again. The whole step will look like this:

7. In this step, we will copy two files: Vending.apk andGoogleServicesFramework.apk into /system/app. To do this, from the second command prompt window, type: adb -s emulator-5554 push Vending.apk /system/app/. and hit Enter. Similar to that, to copy the next file, type: adb -s emulator-5554 push GoogleServicesFramework.apk /system/app/. , hit Enter again. If sucess, it will look like this:

8. Now, you need to remove SdkSetup.apk from /system/app (if it is not removed, the SDK will be restore in next session). In the second command prompt window, type: adb shell rm /system/app/SdkSetup.apk , hit Enter.

9. Close your emulator.

10. Go to C:\Users\Username\.android\avd\Emulator’s name.avd and delete these two filesuserdata-qemu.img and cache.img. Launch your emulator in the normal way and then, you will see Android Market from the list.


Using Facebook:


Note: Some applications and games may not work because they need real hardware. Angry Birds and Youtube are such examples. With these you can hear the sounds but not see any video.

 

Referenced by: http://www.tech-recipes.com/rx/10004/accessing-android-market-from-android-sdk/

 
1 Comment

Posted by on March 29, 2012 in Android

 

Android Series: Download files with Progress Dialog

Android Series: Download files with Progress Dialog

Today, I will present a short tutorial on how to download files in android displaying at the same time download progress based on the bytes downloaded. For the purpose of this tutorial we will use build in AsyncTask mechanism together with ProgressDialog class.
The whole application consists of one activity displaying a ‘Start Download’ button. Clicking our startbutton we initialize file download passing to the asynctask the url or the resource we want to download.


AndroAsync.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.softwarepassion;

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class AndroAsync extends Activity {

public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
private Button startBtn;
private ProgressDialog mProgressDialog;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startBtn = (Button)findViewById(R.id.startBtn);
startBtn.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
startDownload();
}
});
}

private void startDownload() {
String url = “http://farm1.static.flickr.com/114/298125983_0e4bf66782_b.jpg”;
new DownloadFileAsync().execute(url);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DOWNLOAD_PROGRESS:
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(“Downloading file..”);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(false);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}
class DownloadFileAsync extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}

@Override
protected String doInBackground(String… aurl) {
int count;

try {
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();

int lenghtOfFile = conexion.getContentLength();
Log.d(“ANDRO_ASYNC”, “Lenght of file: ” + lenghtOfFile);

InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(“/sdcard/some_photo_from_gdansk_poland.jpg”);

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
publishProgress(“”+(int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}

output.flush();
output.close();
input.close();
} catch (Exception e) {}
return null;

}
protected void onProgressUpdate(String… progress) {
Log.d(“ANDRO_ASYNC”,progress[0]);
mProgressDialog.setProgress(Integer.parseInt(progress[0]));
}

@Override
protected void onPostExecute(String unused) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
}
}

layout file (main.xml) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello”
/>
<Button
android:text=”Start long running task..”
android:id=”@+id/startBtn”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”>
</Button>
</LinearLayout>

While downloadin a file from the internet remember to add INTERNET permission in AndroidManifest.xml

1
<uses-permission android:name=”android.permission.INTERNET” />

Check your sd card folder for what was downloaded and enjoy!

 

Referenced by: http://www.softwarepassion.com/android-series-download-files-with-progress-dialog/

 
1 Comment

Posted by on March 26, 2012 in Android

 

លេងហ្គេមរបស់ម៉ាស៊ីន PS2 នៅលើកុំព្យូទ័រ ជាមួយនិង Best Configuration

មិត្តអ្នកអានមួយចំនួន បានស្គាល់ពីម៉ាស៊ីនហ្គេម PS2 ហើយថាវាជាម៉ាស៊ីនហ្គេមដែលមានប្រជាប្រិយភាព ក្នុងពេលបច្ចុប្បន្ននេះ ទោះបីជាម៉ាស៊ីនហ្គេមនេះស្ថិតនៅសេរីចាស់ មិនដូចម៉ាស៊ីនហ្គេមជំនាន់ថ្មីដូចជា XBOX 360, Wii, PS3 ក៏ដោយ ប៉ុន្តែហ្គេមរបស់វានូវតែត្រូវបានមនុស្សជាច្រើនលាននាក់នៅលើពិភពលោកលេងកម្សាន្ត ហើយថែមទាំងត្រូវបានគេកោតសរសើថាល្អ ពិតជាសប្បាយលេងថែមទៀត។

ដូច្នេះថ្ងៃនេះ CM បានយកកម្មវិធីមួយដែលត្រូវបានគេស្គាល់ថាជាកម្មវិធីលេងហ្គេម PS2 លើកុំព្យូទ័រ ល្អជាងគេនិងឈានមុខគេមកបង្ហាញប្រាប់មិត្តអ្នកអាន។ កម្មវិធីនេះឈ្មោះថា PCSX2 ជំនាន់ទី0.98 r4600ហើយ CM យើងបានរៀបចំនូវ Plug-in with Biosដើម្បីឱ្យហ្គេមរបស់យើងលេងហ្គេមបានស្រួល និង សម្លេងគ្មានភាពរអាក់រអួលផងដែរ។

Download :  Visual C++ 2010 (x86) runtime package  (ចាំបាច់សម្រាប់ដំណើរការកម្មវិធី)

Download : PCSX2

តម្រូវការកម្មវីធី

សម្រាប់ម៉ាស៊ីនទាបបំផុត ល្បឿនហ្គេម (90-95%)

    • CPU : Intel Dual Core 1.7Ghz
    • Ram : 1GB
    • VGA: 128MB

សម្រាប់ម៉ាស៊ីនដែលដំណើរការស្រួល ល្បឿនហ្គេម (95-100%)

    • CPU : Intel Core 2 Duo 2.0Ghz
    • Ram : 1GB
    • VGA: 512 MB

វិធី Configuration ទីតាំងរបស់ Plug-in និង Biosដំបូង

នៅពេលដំណើរការដំបូងវាទាមទារឱ្យយើងជ្រើសរើសទីតាំង Plug-in, Bios និង Memory Card ជាដើម។

តែយើងក៏អាច Configuration ទីតាំងនេះសារជាថ្មីម្តងទៀតដោយចូលទៅកាន់

Config => Plugin/Bios Selector រួចកំណត់ដូចខាងក្រោមៈ

វិធីសាស្រ្ត Configuration ដើម្បីឱ្យហ្គេមលេងបានស្រួលនិងមានល្បឿនលឿន

  • ភាពខុសគ្នារវាង Disc ឬ ISO ប្រភេទ NTSC និង PAL

NTSC មានល្បឿនលឿនជាង PAL ព្រោះ speed របស់ វាដល់ទៅ 60fps, ប៉ុន្តែរូបភាព និង សម្លេងអន់បន្តិច តែយើងគួរប្រើប្រាស់Disc ឬ ISO ប្រភេទ NTSC នេះព្រោះវាអាចជួយឱ្យយើងលេង ហ្គេមបានលឿន ជាមួយរូបភាពដែលអាចទទួលយកបាន។

PAL មានល្បឿនយឺត speed របស់វាត្រឹមតែ 50fps ប៉ុន្តែរូបភាពស្អាត និង សម្លេងច្បាស់ល្អ ។ យើងអាចលេងហ្គេមវាបានលុះត្រាតែម៉ាស៊ីនកុំព្យូទ័ររបស់យើងខ្ពស់។

  • ភាពខុសគ្នារវាង Gsdx9 Hardware និង Software :   (ចូលទៅកាន់ Config => Video GS => Plugin setting)
  • ប្រសិនបើយើងជ្រើសរើសយក Gsdx9: Direct3D9 Hardware វាមានល្បឿនលឿនក្នុងការលេង ប៉ុន្តែវា មិន Support ល្អទេចំពោះ Disc ឬ ISO ប្រភេទ NTSC។ ប្រសិនបើដំណើរការហ្គេមមិនឃើញរូបជាមួយ Disc ឬ ISO ប្រភេទ NTSC សូមចុច F5។
  • តែបើយើងជ្រើសរើសយក Gsdx9: Direct3D9 Software វិញ វាបច្ចេញរូបភាពដូច PS2 តែម្តង ហើយ Support គ្រប់ប្រភេទ Disc ឬ ISO ប្រភេទ NTSC តែវាមានល្បឿនយឺតបន្តិច តែបើ PC យើងកម្រិតខ្ពស់គឺគ្មានបញ្ហាទេ។
    • ការកែរប្រែមួយចំនួនដើម្បីឱ្យហ្គេម PS2 ដើរលឿន:
    • ប្រើប្រាស់ Disc ឬ ISO ប្រភេទ NTCS :
    • ប្រើប្រាស់ Gsdx9 : Direct3D9 Hardware ជាមួយនិងការ Tick យក Native
    • កែរសម្រួលជម្រើសមួយចំនួនដូចខាងក្រោមៈចូលទៅកាន់ Config => Emulation settings

របៀបដាក់ ISO ទៅក្នុង Emulator

CDVD => Iso Selector => Browsers រួចរកទីតាំងរបស់ ISO File ជាការស្រេច។

របៀបដាក់ ដំណើរការហ្គេម

System => Boot CDVD Full

x ប្រសិនបើយើងជ្រើសរើសយក Gsdx9: Direct3D9 Hardware វាមានល្បឿនលឿនក្នុងការលេង ប៉ុន្តែវា មិន Support ល្អទេចំពោះ Disc ឬ ISO ប្រភេទ NTSC។ ប្រសិនបើដំណើរការហ្គេមមិនឃើញរូបជាមួយ Disc ឬ ISO ប្រភេទ NTSC សូមចុច F5។

Referenced by: http://cm.com.kh/2012/03/emulator-ps2-pcsx2/?fb_ref=AL2FB&fb_source=tickerdialog_oneline

 
Leave a comment

Posted by on March 12, 2012 in General

 

Android Honeycomb: NetworkOnMainThreadException even when using AsyncTask and no strict mode?

By Jorgesys

I run into a NetworkOnMainThreadException with my Android 3.0 app. Searching for a solution I foundthis, but if I understand this correctly, default setting would be that the strict mode is turned off.

Also, all my network access is in an AsyncTask, so I don’t see the point in this Exception anyway.

So, I’m quite desperate now what I should do to prevent this…

Kind regards, jellyfish

Edit:

This blog entry says that AsyncTask should be enough, but at least clarifies the StrictMode point.

Solution:

I turned off the StrictMode (its probably better to keep some settings but I couldn’t be bothered…):

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

After that, I did run into a “java.lang.RuntimeException: This thread forbids HTTP requests”, but found a solution for this here. I’m a bit confused, though, as AndroidHttpClient worked fine when I used it in my Android 2.0+ app…

Solution, part2

As it turned out, using AsyncTask was a nice idea but pretty useless if done wrong… So there was nothing wrong with the strict mode’s reaction. Should have listened, er? 😉

Still good to know it’s activated on Honeycomb by default.

 

In Android Honeycomb StrictMode is enabled, turn it off adding the code on the onCreate() function…

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);       
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

 

Referenced by: http://stackoverflow.com/questions/6277584/android-honeycomb-networkonmainthreadexception-even-when-using-asynctask-and-no/7986490#7986490

 
Leave a comment

Posted by on March 2, 2012 in Android