I just updated my OS to win 7 64-bit. I can use all 6 GB of RAM. But the Android Development really gave me trouble. The Eclipse 64-bit might be a good idea but it requires Java-64. Java-64 might conflict with other 32-bit application. In the end, I have to use Java-32 and Eclipse 32.
After Eclipse is installed, you need go to Help->Update Software. That will install the Android Plugin for Eclipse. Once the plugin is installed, you can install Android SDK and point the Android SDK directory in Eclipse.
Since there are many things to download in the Android SDK and I am tired of downloading, I decided to use the old Android SDK directory.
After the Android SDK is pointed to the right directory, you can start developing. Using virtual machine is no problem. If you want to use the real devices, you have to install ADB driver. The driver will recognize your device through USB cable. Common drivers are installed in the Androids SDK usb_driver directory.
For LG Ally, there is an LG driver you need to install. Once you have that installed, everything will be fine.
Sunday, December 26, 2010
Friday, December 3, 2010
How to post rating
myRating = new RatingBar(this); //Create a rating bar.
myRating_Label = new TextView(this); //Create a label;
myRatingView = new LinearLayout(this); //Create a LinearLayout
myRatingView.setOrientation( LinearLayout.VERTICAL );
myRatingView.addView(myRating_Label); //Add the label to the View
myRatingView.addView(myRating); //Add rating bar to the View
alert = new AlertDialog.Builder(this).create(); //Create a AlertDialog
alert.setView(myRatingView); //Add the Rating View to the alert
// Add a button to the Alert
alert.setButton("Submit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = "Thanks for your rating " + String.valueOf(User_Rating);
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_SHORT).show();
}
});
Create menu
When the Menu button is press on the phone, you can show up a menu to let user do something
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode == KeyEvent.KEYCODE_MENU) {
AlertDialog.Builder dialogBuilder =
new AlertDialog.Builder(this)
.setMessage("Dialog Message")
.setTitle("The Title");
dialogBuilder.create().show();
return true;
}
return super.onKeyDown(keyCode, event);
}
Thursday, November 18, 2010
Fetch data from html
public void Fetch_Data(){
line = "";
try {
// Perform action on click
//Log.w("Fetchhhhhhhhhhhhh","You are going to fetch tip data");
String tempStr = "";
// Initiate the url connection
URL url = new URL(The_URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ( (tempStr= rd.readLine()) != null) {
line = line + tempStr;
}
rd = null;
conn.disconnect();
}
catch (Exception e) {
Log.w("===========",e);
}
}
How to use Spinner
private ListGame_Mode_List for (int i=0;i < Game_Mode.length ;i++) { // Populate the Game_Mode List Game_Mode_List.add(Game_Mode[i]); } // Put the Game_Mode_List to an Addapter and set addapter tpye ArrayAdapter Game_Mode_Addapter = new ArrayAdapter ( this, android.R.layout.simple_spinner_dropdown_item, Game_Mode_List); Game_Mode_Addapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item ); // Create Spinner and attach the addapter to it. Spinner Game_Mode_Spinner = new Spinner(this); Game_Mode_Spinner.setAdapter(Game_Mode_Addapter); // The listener will listen the change. arg2 is the item selected Game_Mode_Spinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { myGameMode = String.valueOf(arg2); } @Override public void onNothingSelected(AdapterView arg0) { myGameMode = "1"; } } );
Tuesday, November 16, 2010
Program Android on Mac
According to some websites, in order to develop android device on a Mac, all you need to do is to add the adb tool path to your .bash_profile. There is a script that do that for you. adb for Mac
In addition to that, it seems the cable also play an important role. The cable comes with MID does not work. Only the cable comes with the LG ally can work with Eclipse.
http://northmendo.com/downloads/Install_adb.dmg
In addition to that, it seems the cable also play an important role. The cable comes with MID does not work. Only the cable comes with the LG ally can work with Eclipse.
Wednesday, November 10, 2010
Send data to php
A php can read "POST" data. The following code can be used.
public void Fetch_Html() {
try {
String Data_username = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode("Test username", "UTF-8");
String Data_email = URLEncoder.encode("email", "UTF-8") + "=" + URLEncoder.encode("Test Email", "UTF-8");
String Data_tip = URLEncoder.encode("tip", "UTF-8") + "=" + URLEncoder.encode("This tip", "UTF-8");
String Quest_Data = Data_username + "&" + Data_email + "&" + Data_tip;
The_URL = "http://ad-mountain.com/tipSubmit.php";
// Initiate the url connection
URL url = new URL(The_URL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Charset", "UTF-8");
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded" );
conn.setRequestProperty("Content-Length", "" + Integer.toString(Quest_Data.getBytes().length));
conn.connect();
DataOutputStream ds = new DataOutputStream(conn.getOutputStream());
ds.writeBytes(Quest_Data);
ds.flush();
Log.w("=========", Quest_Data);
conn.disconnect();
ds.close();
}
catch (Exception e) {}
}
Sunday, November 7, 2010
Good Android Resources
http://ophonesdn.com/forum/archiver/fid-5.html
and
http://ophonesdn.com/forum/index.jsp
and
http://ophonesdn.com/forum/index.jsp
Friday, November 5, 2010
Make Android connection
Update: Actually, both of the following code would work on my S7 and Ally. The headset I tried has only one profile implemented. That's the reason it can not be found by S7.
The following code is suggested.
mmSocket = device.createRfcommSocketToServiceRecord(MY_UUID); mmSocket.connect();
The following code is suggested.
private static String address = "00:19:7F:1F:20:DF";
private BluetoothSocket btSocket = null;
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
Method m = null;
m = device.getClass().getMethod("createRfcommSocket", new Class[]{int.class});
btSocket = (BluetoothSocket)m.invoke(device, Integer.valueOf(1));
btSocket.connect();
Sunday, October 31, 2010
Computer setup
The new computer client setup is not hard. Sever things I have noticed.
/etc/fstab 192.168.57.18:/home /home nfs nodev,rw,nosuid,relatime 0 0 192.168.57.18:/cad /cad nfs nodev,ro,nosuid,relatime 0 0 install java for eclipse sudo apt-get install java-sdk
Sunday, August 29, 2010
Update UI with handler
package com.example.hellol10n;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class HelloL10N extends Activity {
private TextView txtStatus;
private TextView txtViewer;
private RefreshHandler mRedrawHandler = new RefreshHandler();
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
HelloL10N.this.updateUI();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
private void updateUI(){
int currentInt = Integer.parseInt((String) txtStatus.getText()) + 10;
if(currentInt <= 100){
mRedrawHandler.sleep(1000);
txtStatus.setText(String.valueOf(currentInt));
txtViewer.setText(String.valueOf(currentInt*100));
}
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
this.txtStatus = (TextView) this.findViewById(R.id.TimerView);
this.txtViewer = (TextView) this.findViewById(R.id.StatusView);
updateUI();
}
}
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class HelloL10N extends Activity {
private TextView txtStatus;
private TextView txtViewer;
private RefreshHandler mRedrawHandler = new RefreshHandler();
class RefreshHandler extends Handler {
@Override
public void handleMessage(Message msg) {
HelloL10N.this.updateUI();
}
public void sleep(long delayMillis) {
this.removeMessages(0);
sendMessageDelayed(obtainMessage(0), delayMillis);
}
};
private void updateUI(){
int currentInt = Integer.parseInt((String) txtStatus.getText()) + 10;
if(currentInt <= 100){
mRedrawHandler.sleep(1000);
txtStatus.setText(String.valueOf(currentInt));
txtViewer.setText(String.valueOf(currentInt*100));
}
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
this.txtStatus = (TextView) this.findViewById(R.id.TimerView);
this.txtViewer = (TextView) this.findViewById(R.id.StatusView);
updateUI();
}
}
How to use button, spinner and buttonlistener
package md.ap;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.view.View;
public class fun_app extends Activity
{
Spinner spinner1;
Button button1;
EditText text1;
@Override
protected void onCreate(Bundle icicle)
{
super.onCreate(icicle);
//setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.main);
spinner1 = (Spinner) findViewById (R.id.spinner1);
button1 = (Button) findViewById (R.id.button1);
text1 = (EditText) findViewById (R.id.text1);
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, array_List);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter);
button1.setOnClickListener( new clicker());
}
private static final String[] array_List = {"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" };
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String s = (String) spinner1.getSelectedItem();
text1.setText(s);
}
}
}
Get webpage
package md.app.getweb;
import android.app.Activity;
import android.os.Bundle;
// used for interacting with user interface
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.text.Html;
import android.view.View;
// used for passing data
import android.os.Handler;
import android.os.Message;
// used for connectivity
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
//import md.ap.fun_app.clicker;
public class getwebpage extends Activity {
/** Called when the activity is first created. */
Handler h;
EditText eText;
TextView tView;
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
eText = (EditText) findViewById(R.id.address);
tView = (TextView) findViewById(R.id.pagetext);
//eText.setText("https://calendar.ndsu.nodak.edu/ocas-bin/ocas.fcgi?sub=web&web=gbl&viw=J8EhJH%2baDZv%2bU4bFfdqycQ%3d%3d&xen=zU5cb5yAJWlv1iofkpGceQ%3d%3d&server=tbtzPzHLjyw%3d&ver=2");
this.h = new Handler() {
@Override
public void handleMessage(Message msg) {
// process incoming messages here
switch (msg.what) {
case 0:
tView.append((String) msg.obj);
break;
}
super.handleMessage(msg);
}
};
Button button = (Button) findViewById(R.id.ButtonGo);
clicker test = new clicker();
test.onClick(tView);
button.setOnClickListener( new clicker());
// button.setOnClickListener(new Button.OnClickListener() {
}
class clicker implements Button.OnClickListener{
public void onClick(View v) {
try {
tView.setText("");
// Perform action on click
URL url = new URL(eText.getText().toString());
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
String My_Html = "";
while ((line = rd.readLine()) != null) {
Message lmsg;
lmsg = new Message();
lmsg.obj = line;
//lmsg.obj = Html.fromHtml(line);
lmsg.what = 0;
//System.out.println(line);
//System.out.println(Html.fromHtml(line));
getwebpage.this.h.sendMessage(lmsg);
My_Html = My_Html + line;
System.out.println(My_Html);
}
}
catch (Exception e) {
}
}
}
}
import android.app.Activity;
import android.os.Bundle;
// used for interacting with user interface
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.text.Html;
import android.view.View;
// used for passing data
import android.os.Handler;
import android.os.Message;
// used for connectivity
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
//import md.ap.fun_app.clicker;
public class getwebpage extends Activity {
/** Called when the activity is first created. */
Handler h;
EditText eText;
TextView tView;
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
eText = (EditText) findViewById(R.id.address);
tView = (TextView) findViewById(R.id.pagetext);
//eText.setText("https://calendar.ndsu.nodak.edu/ocas-bin/ocas.fcgi?sub=web&web=gbl&viw=J8EhJH%2baDZv%2bU4bFfdqycQ%3d%3d&xen=zU5cb5yAJWlv1iofkpGceQ%3d%3d&server=tbtzPzHLjyw%3d&ver=2");
this.h = new Handler() {
@Override
public void handleMessage(Message msg) {
// process incoming messages here
switch (msg.what) {
case 0:
tView.append((String) msg.obj);
break;
}
super.handleMessage(msg);
}
};
Button button = (Button) findViewById(R.id.ButtonGo);
clicker test = new clicker();
test.onClick(tView);
button.setOnClickListener( new clicker());
// button.setOnClickListener(new Button.OnClickListener() {
}
class clicker implements Button.OnClickListener{
public void onClick(View v) {
try {
tView.setText("");
// Perform action on click
URL url = new URL(eText.getText().toString());
URLConnection conn = url.openConnection();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line = "";
String My_Html = "";
while ((line = rd.readLine()) != null) {
Message lmsg;
lmsg = new Message();
lmsg.obj = line;
//lmsg.obj = Html.fromHtml(line);
lmsg.what = 0;
//System.out.println(line);
//System.out.println(Html.fromHtml(line));
getwebpage.this.h.sendMessage(lmsg);
My_Html = My_Html + line;
System.out.println(My_Html);
}
}
catch (Exception e) {
}
}
}
}
Subscribe to:
Posts (Atom)