Archive for the ‘Android’ Category

[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.

/Users/myacountname/.android/adb_usb.ini

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

0x054c

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] Get RSS from network and parse it

Sunday, October 16th, 2011

I tried to get cnet.com RSS and parse it.

mainActivity.java

package com.demo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import android.app.Activity;
import android.os.Bundle;

public class HttpGetDemoActivity extends Activity {
	private ArrayList articles;
	private final String ITEM = "item";
	private final String TITLE = "title";
	private final String PUB_DATE = "pubDate";
	private final String GUID = "guid";
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        loadXML();
    }
    
    private void loadXML() {
        BufferedReader in = null;
        String xmlStr = "";
        try{
        	String url = "http://news.cnet.com/8300-1_3-1.xml?categoryId=1999&keywords=Gadget%20news";
        	HttpClient client = new DefaultHttpClient();
        	HttpGet request = new HttpGet(url);
        	HttpResponse responce = client.execute(request);
        	
        	in = new BufferedReader(new InputStreamReader(responce.getEntity().getContent()));
        	
        	StringBuffer sb = new StringBuffer("");
        	String line = "";
        	String NL = System.getProperty("line.separator");
        	while((line = in.readLine()) != null){
        		sb.append(line + NL);
        	}
        	in.close();
        	
        	xmlStr = sb.toString();
        	//System.out.println(page);
        	
        }catch(Exception e){
        	e.printStackTrace();
        }finally{
        	if(in != null){
        		try{
        			in.close();
        		}catch(IOException e){
        			e.printStackTrace();
        		}
        	}
        }
        
        try{
        	parseXML(xmlStr);
        }catch(IOException e){
        	e.printStackTrace();
        }catch(XmlPullParserException e){
        	e.printStackTrace();
        }
	}

	public void parseXML (String xmlStr) throws XmlPullParserException, IOException
    {
    	XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    	factory.setNamespaceAware(true);
    	XmlPullParser xpp = factory.newPullParser();
    	
    	xpp.setInput(new StringReader(xmlStr));
    	int eventType = xpp.getEventType();


    	Boolean isItem = false;
    	ArticleData articleData = null;
    	
    	while(eventType != XmlPullParser.END_DOCUMENT){
    		String xmlNodeName;
    		
    		switch(eventType){
    			case XmlPullParser.START_DOCUMENT:
    				articles = new ArrayList();
    				break;
    			case XmlPullParser.START_TAG:
    				xmlNodeName = xpp.getName();
    				if(xmlNodeName.equalsIgnoreCase(ITEM)){
    					isItem = true;
    					articleData = new ArticleData();
    				}
    				if(isItem){
        				if(xmlNodeName.equalsIgnoreCase(TITLE)){
        					articleData.title = xpp.nextText();
        				}else if(xmlNodeName.equalsIgnoreCase(PUB_DATE)){
        					articleData.pubDate = xpp.nextText();
        				}else if(xmlNodeName.equalsIgnoreCase(GUID)){
        					articleData.guid = xpp.nextText();
        				}
    				}
    				break;
    			case XmlPullParser.END_TAG:
    				xmlNodeName = xpp.getName();
    				if(xmlNodeName.equalsIgnoreCase(ITEM)){
    					isItem = false;
    					articles.add(articleData);
    				}
    				break;
    		}
    		
    		eventType = xpp.next();
    	}
    }
}

ArticleData.java

package com.demo;

public class ArticleData {
	String title;
	String pubDate;
	String guid;
}

XMLPullParseSample was from this site. Thank you!
>> Consuming A SOAP Web Service: XmlPullParser Alternative

[Android] Permit Internet access

Friday, October 14th, 2011

in AndroidManifest.xml


[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.

[Android] How to access to external sd card in Galaxy Tab from browser

Tuesday, July 12th, 2011

Input browser this path.

file:///sdcard/external_sd/

And you need add the content path.
For example, if there is your sd card’s content on root.

file:///sdcard/external_sd/index.html

If there is a folder,

file:///sdcard/external_sd/myfolder/index.html