tag:blogger.com,1999:blog-33372480914256131332024-03-13T10:28:13.747-07:00CHILDLY ANDROIDHERE ANDROID ARE GROWINGUnknownnoreply@blogger.comBlogger13125tag:blogger.com,1999:blog-3337248091425613133.post-23932556767180307332012-10-30T06:51:00.005-07:002012-10-30T06:51:59.421-07:00what is meant by Stick IntentsIts interview questions i search some sites my knowledge to share to you.<br />
<br />
<span style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px;">A normal broadcast </span><code class="code" style="background-color: white; font-size: 16px;">Intent</code><span style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px;"> is not available anymore after is was send and processed by the system. If you use the </span><code class="code" style="background-color: white; font-size: 16px;">sendStickyBroadcast(Intent)</code><span style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px;"> method, the </span><code class="code" style="background-color: white; font-size: 16px;">Intent</code><span style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px;"> is sticky, meaning the </span><code class="code" style="background-color: white; font-size: 16px;">Intent</code><span style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px;">you are sending stays around after the broadcast is complete.</span>
<br />
<span style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px;"><br /></span>
<br />
<pre class="programlisting" style="background-color: #ffffee; border-bottom-left-radius: 9px; border-bottom-right-radius: 9px; border-top-left-radius: 9px; border-top-right-radius: 9px; border: 1px solid rgb(187, 187, 187); font-family: 'Droid Sans Mono', Monaco, 'Bitstream Vera Sans Mono', 'Lucida Console', Terminal, monospace; font-size: 13px; line-height: 16px; margin: 10px; overflow: auto; padding: 1em; word-wrap: break-word;"><em class="hl-comment" style="color: #008800;">// Register for the battery changed event</em>
IntentFilter filter = <span class="hl-keyword" style="color: #7f0055; font-weight: bold;">new</span> IntentFilter(Intent.ACTION_BATTERY_CHANGED);
/ Intent is sticky so using null as receiver works fine
<em class="hl-comment" style="color: #008800;">// return value contains the status</em>
Intent batteryStatus = <span class="hl-keyword" style="color: #7f0055; font-weight: bold;">this</span>.registerReceiver(null, filter);
<em class="hl-comment" style="color: #008800;">// Are we charging / charged?</em>
<span class="hl-keyword" style="color: #7f0055; font-weight: bold;">int</span> status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -<span class="hl-number">1</span>);
<span class="hl-keyword" style="color: #7f0055; font-weight: bold;">boolean</span> isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
|| status == BatteryManager.BATTERY_STATUS_FULL;
<span class="hl-keyword" style="color: #7f0055; font-weight: bold;">boolean</span> isFull = status == BatteryManager.BATTERY_STATUS_FULL;
<em class="hl-comment" style="color: #008800;">// How are we charging?</em>
<span class="hl-keyword" style="color: #7f0055; font-weight: bold;">int</span> chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -<span class="hl-number">1</span>);
<span class="hl-keyword" style="color: #7f0055; font-weight: bold;">boolean</span> usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
<span class="hl-keyword" style="color: #7f0055; font-weight: bold;">boolean</span> acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC; </pre>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
</div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
Sticky <em class="wordasword">Broadcast Intents</em> typically require special permissions. <a href="http://www.vogella.com/articles/AndroidBroadcastReceiver/article.html" target="_blank">reference link</a></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
first u understand intents and intents filters:</div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
its also nice blog are here:<a href="http://castlerockresearch.in/blog/dev/2010/08/15/understanding-intents-and-intent-filters-in-android/" target="_blank">intents and filters</a></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
and u study services also: <a href="http://www.vogella.com/articles/AndroidServices/article.html" target="_blank">services</a></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
<div style="background-color: white; font-family: Lato, arial, sans-serif; font-size: 16px; line-height: 24px; margin-left: 10px; margin-right: 10px;">
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-28931830837062260602012-10-24T01:57:00.001-07:002012-10-30T01:37:02.644-07:00convert text to url.<br />
Linkify is used to convert text to link and text to dial phone number also used.<br />
<br />
so we used us Linkify.ALL method.<br />
<br />
<br />
TextView link = (TextView) findViewById(R.id.link);<br />
<br />
link.setText("www.google.com");<br />
Linkify.addLinks(link, Linkify.ALL);<br />
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-62820965013042319322012-09-21T00:43:00.000-07:002012-09-21T00:45:30.311-07:00SENDING FILE TO WEB SERVER USING ANDROID<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
FileInputStream fileInputStream = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>fileInputStream = new FileInputStream(image);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (FileNotFoundException e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated catch block<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>e.printStackTrace();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
bitmap=BitmapFactory.decodeStream(fileInputStream);<br />
ByteArrayOutputStream baos = new ByteArrayOutputStream();<br />
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);<br />
byte[] data = baos.toByteArray();<br />
IMAGE= Base64.encodeBytes(data);<br />
Log.e("THE IMAGE BYTES",""+IMAGE);<br />
<br />
<br />
<br />
<br />
IMAGE IS STRING TO SEND TO WEB SERVER </div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-52128599885059053992012-09-20T23:35:00.000-07:002012-09-20T23:35:53.464-07:00how to find file path extension and size not exceeded to 1 mb in android<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<br />String s="file path";<br />
File file = new File(s);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>long sizeInBytes = file.length();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> sizeInBytes = sizeInBytes/1024;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("login bytes", ""+sizeInBytes);<br />
//transform in MB<br />
//double sizeInMb = sizeInBytes/(1024*1024);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
if(sizeInBytes<=2048)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("login", ""+sizeInBytes);<br />
int dot = c.lastIndexOf(".");<br />
String ff= c.substring(dot+1);<br />
<br />
// tv1.setText(ff);<br />
if(ff=="pdf"||ff.compareTo("txt")==0||ff=="docx"||ff=="doc"||ff=="xls"||ff=="xlsx"||ff=="ppt"||ff=="pptx")<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//Log.e("login if", ""+ff);<br />
exsistingFileName=c;<br />
Log.e("path file", ""+exsistingFileName);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String searchFor = "bit.ly/yyyyyy";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String s1=feed1.getText().toString();<br />
int len = searchFor.length();<br />
int result = 0;<br />
if (len > 0) { <br />
int start = s1.indexOf(searchFor);<br />
while (start != -1) {<br />
result++;<br />
start =s1.indexOf(searchFor, start+len);<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
}<br />
}<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span><br />
if(result==0)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>feed1.append(" bit.ly/yyyyyy ");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
else<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span><br />
}<br />
else<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>showAlertDialog("file type only doc,txt,doc,docx,ppt,xls,xls");<br />
}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//Log.e("path", ""+exsistingFileName);<br />
}<br />
else<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>showAlertDialog("file size not exceed to 2mb");<br />
}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
}<br />
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-42673825590038624032012-09-20T23:32:00.001-07:002012-09-21T04:42:14.997-07:00how to use bit.ly url in ur android program<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
int leng=ulink.length();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> for (int i = 0; i <= (leng - 7);i++) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> if (ulink.regionMatches(i, "http://", 0, 6)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> youtubelink=ulink;}}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> for (int i = 0; i <= (leng - 4);i++) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> if (ulink.regionMatches(i, "www.", 0, 3)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> youtubelink=ulink.replace("www.", "http://");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> youtubelink=youtubelink.trim();}} <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> try{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> url = as("user name", "api key").call(shorten(youtubelink));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String s1=url.getShortUrl();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> feed1.append(" "+s1);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> catch(Exception e)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span>showAlertDialog("please check your url and its wrong");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Do something with value!<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<br />
<br />
<br />
<br />
public class BitActivity extends Activity {<br />
/** Called when the activity is first created. */<br />
@Override<br />
public void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.main);<br />
<br />
<br />
<br />
Url url = as("username", "key").call(shorten("http://google.com"));<br />
String s=url.getShortUrl();<br />
Log.e("url",s);<br />
<br />
URLConnection conn = null;<br />
<br />
conn = connectURL(s);<br />
<br />
String sss=conn.toString();<br />
Log.e("expand",sss);<br />
<br />
<br />
}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>private URLConnection connectURL(String s) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// TODO Auto-generated method stub<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>URLConnection conn =null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> URL inputURL = new URL(s);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn = inputURL.openConnection();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // int test = 0;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }catch(MalformedURLException e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> System.out.println("Please input a valid URL");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }catch(IOException ioe) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> System.out.println("Can not connect to the URL");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return conn;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
<br />
<br />
<br />
its very simple<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> </div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-73518430697047867282012-09-20T23:28:00.001-07:002012-09-20T23:28:17.412-07:00how to get a device id in android phone<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
final TelephonyManager tm = (TelephonyManager) this<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getSystemService(Context.TELEPHONY_SERVICE);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>final String tmDevice, tmSerial, androidId;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>tmDevice = "" + tm.getDeviceId();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>tmSerial = "" + tm.getSimSerialNumber();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>androidId = ""<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>+ android.provider.Settings.Secure.getString(this<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.getContentResolver(),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>android.provider.Settings.Secure.ANDROID_ID);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>.hashCode() << 32)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>| tmSerial.hashCode());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>DID = deviceUuid.toString();<br />
<br />
<br />
important user permission is <span class="Apple-tab-span" style="white-space: pre;"> </span><uses-permission android:name="android.permission.READ_PHONE_STATE"/><br />
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-53801886516500663332012-08-31T23:29:00.000-07:002012-09-10T03:05:06.746-07:00KSOAP2 USING SEND IMAGE TO WEB SERVER IN ANDROID<div dir="ltr" style="text-align: left;" trbidi="on">
its ksoap codes to send image and file to web server :<br />
<br />
<br />
<br />
public class SoapuploadActivity extends Activity {<br />
/** Called when the activity is first created. */<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public final String SOAP_ACTION = "http://tempuri.org/Add";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public final String OPERATION_NAME = "Add";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public final String SOAP_ADDRESS = "http://grasshoppernetwork.com/NewFile.asmx";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> TextView tv;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
@Override<br />
public void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.main);<br />
<br />
tv=(TextView)findViewById(R.id.textView2);<br />
<br />
Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ByteArrayOutputStream baos = new ByteArrayOutputStream();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>bMap .compress(Bitmap.CompressFormat.PNG, 100, baos);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//bMap is the bitmap object<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>byte[] b = baos.toByteArray();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>int i=b.length;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("the output is",""+i);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span style="white-space: pre;"> String IMAGE= Base64.encodeBytes(b);</span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Call(IMAGE);<br />
<br />
}<br />
<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void Call(byte[] b)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>PropertyInfo pi=new PropertyInfo();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
pi=new PropertyInfo();<br />
pi.setName("b");<br />
pi.setValue(b);<br />
pi.setType(byte[].class);<br />
request.addProperty(pi);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>SoapEnvelope.VER11);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>envelope.dotNet = true;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>envelope.setOutputSoapObject(request);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Object response=null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>httpTransport.call(SOAP_ACTION, envelope);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>response = envelope.getResponse();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>catch (Exception exception)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>response=exception.toString();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("the error is",""+response);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e("the output is",""+response);<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>tv.setText(response.toString());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
}<br />
<br />
<br />
<br />
its download and add library file to project: <a href="http://code.google.com/p/koslan/downloads/detail?name=ksoap2-j2se-full-2.1.2.jar&can=2&q=" target="_blank">link</a><br />
its download and add base64conversion to project: <a href="http://migbase64.sourceforge.net/" target="_blank">base 64</a><br />
<br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-70848552356950714962012-08-31T23:25:00.002-07:002012-09-20T23:23:31.606-07:00CONTENT TYPE USING SEND IMAGE OR FILE TO WEB SERVER IN ANDROID<div dir="ltr" style="text-align: left;" trbidi="on">
its send file or image send to web server:<br />
<br />
This is content value type :<br />
<br />
<br />
<br />
private void doFileUpload(){<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> HttpURLConnection conn = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> DataOutputStream dos = null;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> DataInputStream inStream = null;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> z=1;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Is this the place are you doing something wrong.<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String lineEnd = "\r\n";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String twoHyphens = "--";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String boundary = "*****";<br />
String exsistingFileName="given to file path";<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> int bytesRead, bytesAvailable, bufferSize;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> byte[] buffer;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> int maxBufferSize = 1*1024*1024;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String responseFromServer = "";<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String urlString = "server url";<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> try<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> //------------------ CLIENT REQUEST<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer","Inside second Method");<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName) );<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // open a URL connection to the Servlet<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> URL url = new URL(urlString);<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Open a HTTP connection to the URL<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn = (HttpURLConnection) url.openConnection();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Allow Inputs<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.setDoInput(true);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Allow Outputs<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.setDoOutput(true);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Don't use a cached copy.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.setUseCaches(false);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // Use a post method.<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.setRequestMethod("POST");<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.setRequestProperty("Connection", "Keep-Alive");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos = new DataOutputStream( conn.getOutputStream() );<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.writeBytes(twoHyphens + boundary + lineEnd);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + exsistingFileName +"\"" + lineEnd);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.writeBytes(lineEnd);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer","Headers are written");<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // create a buffer of maximum size<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> bytesAvailable = fileInputStream.available();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> bufferSize = Math.min(bytesAvailable, maxBufferSize);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> buffer = new byte[bufferSize];<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // read file and write it into form...<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> bytesRead = fileInputStream.read(buffer, 0, bufferSize);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> while (bytesRead > 0)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.write(buffer, 0, bufferSize);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> bytesAvailable = fileInputStream.available();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> bufferSize = Math.min(bytesAvailable, maxBufferSize);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> bytesRead = fileInputStream.read(buffer, 0, bufferSize);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // send multipart form data necesssary after file data...<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.writeBytes(lineEnd);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> BufferedReader in = new BufferedReader(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span>new InputStreamReader(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> conn.getInputStream()));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String inputLine;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>while ((inputLine = in.readLine()) != null)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>tv.append(inputLine);<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> // close streams<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer","File is written");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> fileInputStream.close();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.flush();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dos.close();<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> catch (MalformedURLException ex)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer", "error: " + ex.getMessage(), ex);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> catch (IOException ioe)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer", "error: " + ioe.getMessage(), ioe);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> //------------------ read the SERVER RESPONSE<br />
<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> inStream = new DataInputStream ( conn.getInputStream() );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> String str;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> while (( str = inStream.readLine()) != null)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer","Server Response"+str);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> inStream.close();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> catch (IOException ioex){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> Log.e("MediaPlayer", "error: " + ioex.getMessage(), ioex);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> }<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
this code just call main activity and the method name is doFileUpload() its working .</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-25645038999208547942012-08-31T23:09:00.002-07:002012-08-31T23:39:39.866-07:00MME USING SEND IMAGE OR FILE TO WEB SERVER IN ANDROID<div dir="ltr" style="text-align: left;" trbidi="on">
hi friends Today see to how to upload a image and file to web server using method<br />
<br />
I'm discuss with few technique and method are:<br />
<br />
1. mime method<br />
2.content type method<br />
3.ksoap method<br />
4.mime with json .<br />
<br />
<br />
mime :<br />
<br />
if its using to add jar file download jar file <a href="http://grepcode.com/snapshot/repo1.maven.org/maven2/org.apache.httpcomponents/httpmime/4.1.2" target="_blank">link</a><br />
<br />
download to the binary file.<br />
<br />
<br />
<br />
public class UploadActivity extends Activity {<br />
/** Called when the activity is first created. */<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Bitmap bm;<br />
@Override<br />
public void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.main);<br />
try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> //bm = BitmapFactory.decodeResource(getResources(),<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> //R.drawable.forest);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>bm = BitmapFactory.decodeFile("/sdcard/DCIM/forest.png");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>executeMultipartPost();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e(e.getClass().getName(), e.getMessage());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>public void executeMultipartPost() throws Exception {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>try {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ByteArrayOutputStream bos = new ByteArrayOutputStream();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>bm.compress(CompressFormat.JPEG, 75, bos);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>byte[] data = bos.toByteArray();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>HttpClient httpClient = new DefaultHttpClient();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>HttpPost postRequest = new HttpPost("your server link");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// File file= new File("/mnt/sdcard/forest.png");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// FileBody bin = new FileBody(file);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>MultipartEntity reqEntity = new MultipartEntity(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>HttpMultipartMode.BROWSER_COMPATIBLE);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>reqEntity.addPart("uploaded", bab);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>postRequest.setEntity(reqEntity);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>HttpResponse response = httpClient.execute(postRequest);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>BufferedReader reader = new BufferedReader(new InputStreamReader(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>response.getEntity().getContent(), "UTF-8"));<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>String sResponse;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>StringBuilder s = new StringBuilder();<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>while ((sResponse = reader.readLine()) != null) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>s = s.append(sResponse);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>System.out.println("Response: " + s);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} catch (Exception e) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// handle exception here<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>Log.e(e.getClass().getName(), e.getMessage());<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<br />
<br />
you just create the project and copy the code and paste and add to library file. Its working.<br />
<br />
<br />
if you want to download a mine with json project just :<a href="http://vikaskanani.wordpress.com/2011/01/29/android-image-upload-activity/" target="_blank">http://vikaskanani.wordpress.com/2011/01/29/android-image-upload-activity/</a><br />
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-30083557750034570492012-08-24T03:30:00.000-07:002012-08-24T03:30:45.083-07:00ANDROID XML PARSER PART 3<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
PULL PARSER:</div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
pull-parsing is the "pull" to SAX parsing's "push". SAX pushes content at you by firing events as it encounters constructs within the xml document. </div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
Pull-parsing lets you ask for (pull) the next significant construct you are interested in.</div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
You still have to take the data in the order it appears in the document - you can't go back and forth through the document like you can with DOM - but you can skip over bits you aren't interested in.</div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
ITS FOR : <a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html" style="background-color: transparent; text-align: left;">http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html</a></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
<div style="background-color: white; color: #222222; line-height: 25px; text-align: -webkit-auto;">
</div>
<div itemprop="articleBody" style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;">
<span style="font-family: Georgia, Times New Roman, serif;"><b>XML Pull Parser is an interface that defines parsing functionality provided in <a href="http://www.xmlpull.org/" style="color: #258aaf; text-decoration: none;">XMLPULL V1 API</a> (visit this website to learn more about API and its implementations).</b></span></div>
<div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;">
<span style="font-family: Georgia, Times New Roman, serif;"><b>There are following different kinds of parser depending on which features are set:</b></span></div>
<ul style="background-color: #f9f9f9; line-height: 19px; margin: 0px 0px 15px 18px; padding: 0px;">
<li style="margin: 0px 0px 4px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>non-validating parser as defined in XML 1.0 spec when FEATURE_PROCESS_DOCDECL is set to true</b></span></li>
<li style="margin: 0px 0px 4px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>validating parser as defined in XML 1.0 spec when FEATURE_VALIDATION is true (and that implies that FEATURE_PROCESS_DOCDECL is true)</b></span></li>
<li style="margin: 0px 0px 4px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>when FEATURE_PROCESS_DOCDECL is false (this is default and if different value is required necessary must be changed before parsing is started) then parser behaves like XML 1.0 compliant non-validating parser under condition that <em>no DOCDECL is present</em> in XML documents (internal entites can still be defined with defineEntityReplacementText()). This mode of operation is intended for operation in constrained environments such as J2ME.</b></span></li>
</ul>
<div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;">
<span style="font-family: Georgia, Times New Roman, serif;"><b>There are two key methods: next() and nextToken(). While next() provides access to high level parsing events, nextToken() allows access to lower level tokens.</b></span></div>
<div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;">
<span style="font-family: Georgia, Times New Roman, serif;"><b>The current event state of the parser can be determined by calling the <a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#getEventType()" style="color: #258aaf; text-decoration: none;">getEventType()</a> method. Initially, the parser is in the <a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#START_DOCUMENT" style="color: #258aaf; text-decoration: none;">START_DOCUMENT</a> state.</b></span></div>
<div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;">
<span style="font-family: Georgia, Times New Roman, serif;"><b>The method <a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#next()" style="color: #258aaf; text-decoration: none;">next()</a> advances the parser to the next event. The int value returned from next determines the current parser state and is identical to the value returned from following calls to getEventType ().</b></span></div>
<div style="background-color: #f9f9f9; line-height: 19px; margin-bottom: 15px;">
<span style="font-family: Georgia, Times New Roman, serif;"><b>Th following event types are seen by next()</b></span></div>
<dl style="background-color: #f9f9f9; line-height: 19px;">
<dt><a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#START_TAG" style="color: #258aaf; text-decoration: none;"><span style="font-family: Georgia, Times New Roman, serif;"><b>START_TAG</b></span></a></dt>
<dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>An XML start tag was read.</b></span></dd>
<dt><a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#TEXT" style="color: #258aaf; text-decoration: none;"><span style="font-family: Georgia, Times New Roman, serif;"><b>TEXT</b></span></a></dt>
<dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>Text content was read; the text content can be retrieved using the getText() method. (when in validating mode next() will not report ignorable whitespace, use nextToken() instead)</b></span></dd>
<dt><a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#END_TAG" style="color: #258aaf; text-decoration: none;"><span style="font-family: Georgia, Times New Roman, serif;"><b>END_TAG</b></span></a></dt>
<dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>An end tag was read</b></span></dd>
<dt><a href="http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html#END_DOCUMENT" style="color: #258aaf; text-decoration: none;"><span style="font-family: Georgia, Times New Roman, serif;"><b>END_DOCUMENT</b></span></a></dt>
<dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>No more events are available</b></span></dd><dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></dd><dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></dd><dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b>SOURCE CODE LINK:<a href="http://www.happygeek.in/xmlpullparser-in-android" target="_blank"> DOWNLOAD</a></b></span></dd><dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;">USEFULL LINK: <a href="http://www.vogella.com/articles/AndroidXML/article.html" target="_blank">TUTORIAL</a></span></dd><dd style="margin: 0px 0px 10px 30px;"><span style="font-family: Georgia, Times New Roman, serif;"><b><br /></b></span></dd></dl>
<br /></div>
Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3337248091425613133.post-75308389243680019222012-08-24T03:21:00.001-07:002012-08-24T03:29:43.676-07:00ANDROID XML PARSER PART 2<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<br />
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding: 0px;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">SAX Parser:</span></strong></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding: 0px;">
<strong style="margin: 0px; padding: 0px;"></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;">SAX stands for Simple API for XML. It uses a "push" approach: whereas with DOM you can dig around in the document in whatever order you like, SAX parsing is event-driven which means you have to handle the data as it is given to you.</span></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;">SAX parsers fire events when they encounter the various components that make up an XML file. You register a <code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">ContentHandler</code> whose methods are called-back when these events occur (for example when the parser finds a new start element, it invokes the startElement method of your<code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">ContentHandler</code>).</span></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;">The API assumes that the consumer (<code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">ContentHandler</code>) is going to maintain some awareness of its state (e.g. where it currently is within the document). I sometimes use a <code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">java.util.Stack</code> to push/pop/peek at which element I'm currently working in, but here I can get away with just recording the name of the current element.</span></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></strong></div>
<div style="color: #222222; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><span style="font-family: Georgia, Times New Roman, serif;">I'm extending <code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">DefaultHandler</code> because I'm not interested in many of the events (it provides a default empty implementation of those methods for me).</span></strong></div>
<div style="color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><br /></strong></div>
<div style="color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;">SOME KEYS POINTS:</strong></div>
<div style="color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; font-weight: normal; line-height: 25px; text-align: -webkit-auto;">
<strong style="margin: 0px; padding: 0px;"><br /></strong></div>
<br />
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-top: 12px; padding: 0px;">
<b style="line-height: 1.5em; text-indent: -0.25in;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="margin: 0px; padding: 0px;">·<span style="line-height: normal; margin: 0px; padding: 0px;"> </span></span>A SAX (<span style="margin: 0px; padding: 0px;">S</span>imple <span style="margin: 0px; padding: 0px;">A</span>PI for <span style="margin: 0px; padding: 0px;">X</span>ML) parser does not create any internal structure. Instead, it takes the occurrences of components of an input document <span style="margin: 0px; padding: 0px;">as events</span>, and tells the client what it reads as it reads through the input document.</span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="margin: 0px; padding: 0px;">·<span style="line-height: normal; margin: 0px; padding: 0px;"> </span></span>A SAX parser serves the client application always only with pieces of the document at any given time.</span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="margin: 0px; padding: 0px;">·<span style="line-height: normal; margin: 0px; padding: 0px;"> </span></span>A SAX parser, however, is much more space efficient in case of a big input document (because it creates no internal structure). What’s more, it runs faster and is easier to learn than DOM parser because its API is really simple. But from the functionality point of view, it provides a fewer functions, which means that the users themselves have to take care of more, such as creating their own data structures.</span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
</div>
<div style="border: 0px; clear: both; color: black; line-height: 18px; margin-bottom: 1em; padding: 0px; text-indent: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>SAX:</b></span></div>
<ol style="border: 0px; color: black; line-height: 18px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; text-indent: 0px; vertical-align: baseline;">
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Parses node by node</b></span></li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Doesnt store the XML in memory</b></span></li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>We cant insert or delete a node</b></span></li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Top to bottom traversing.</b></span></li>
</ol>
<div style="text-indent: 0px;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 18px;"><b><br /></b></span></span></div>
<div style="text-indent: 0px;">
<div style="border: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Sequence of events It doesn't use any memory preferred for large documents. Faster at runtime, because of the above mentioned point. Objects are to be created. Need to write code for creating objects In SAX Backward navigation is not possible as it sequentially processes the document</b></span></div>
<div style="border: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>So if you have very large files then you should use SAX parser since it will fire events and releasing them ,nothing is stored in memory ,and using SAX parser you can't access element in a random way there is no going back ! , but Dom let you access any part of the xml file since it keeps the whole file/document in memory</b></span></div>
<div style="border: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="border: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>EXAMPLE CODE:</b></span></div>
<div style="border: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>SOURCE CODE IS HERE : <a href="http://www.codeproject.com/Articles/334859/Parsing-XML-in-Android-with-SAX" target="_blank">DOWNLOAD</a></b></span></div>
<div style="border: 0px; clear: both; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
</div>
<br />
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
</div>
<div style="color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto; text-indent: 0px;">
<br /></div>
<br />
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="background-color: white; color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-55342732411451076072012-08-24T03:02:00.003-07:002012-08-24T03:30:02.121-07:00ANDROID XML PARSER PART1<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>hi guys ,</b></span><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br />android web services is very important. sending data to web server and receiving data to web server importance. we are using few parsing techniques.</b></span></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br />That's are:</b></span><br />
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> <b> 1. DOM PARSER.</b></span></div>
<div>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> 2. SAX PARSER.</span></b></div>
<div>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> 3. XML PULL PARSER.</span></b></div>
<div>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div>
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">DOM PARSER:</span></b></div>
<div>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">DOM (Document Object Model) parsing builds an in-memory object representation of the entire XML document.</span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> You can then rummage around in the DOM, going and back and forth between elements and reading data from them in whatever order you like.</span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Because the entire document is read into memory, there is an upper limit on the size of document you can read (constrained by the size of your Java heap).</span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Memory is not used particularly efficiently either - a DOM may consist of very many sparsely populated <code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">List</code> objects (backed by mostly empty arrays). </span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">A side effect of all these objects in memory is that when you're finished with them there's a lot for the Garbage Collector to clean up.</span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">On the plus side, DOM parsing is straight-forward to work with, particularly if you don't care much about speed and use <code style="font-size: 17px; letter-spacing: -1px; line-height: 17px;">getElementsByTagName()</code> wherever possible.</span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: white; text-align: -webkit-auto;">
</div>
<div style="border: 0px; clear: both; color: black; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; text-align: left; vertical-align: baseline; word-wrap: break-word;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">DOM Features:</span></b></div>
<ol style="border: 0px; color: black; font-size: 14px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; text-align: left; vertical-align: baseline;">
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Stores the entire XML document into memory before processing.</span></b></li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Occupies more memory.</span></b></li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We can insert or delete nodes.</span></b></li>
<li style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Traverse in any direction.</span></b></li>
</ol>
<div style="text-align: left;">
<span style="font-size: 14px; line-height: 18px;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></span></div>
<div style="text-align: left;">
<span style="font-size: 14px; line-height: 18px;"><b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">some point:</span></b></span></div>
<div style="text-align: left;">
<div class="MsoNormal" style="color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="margin: 0px; padding: 0px;"><span style="line-height: normal; margin: 0px; padding: 0px;"> </span></span><b>A DOM (Document Object Model) parser creates a tree structure in memory from an input document and then waits for requests from client.</b></span></div>
<div class="MsoNormal" style="color: #666666; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="margin: 0px; padding: 0px;">·<span style="line-height: normal; margin: 0px; padding: 0px;"> </span></span>A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client.</span></b></div>
<div class="MsoNormal" style="margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<div style="color: #666666; line-height: 1.5em;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="margin: 0px; padding: 0px;">·<span style="line-height: normal; margin: 0px; padding: 0px;"> </span></span>A DOM parser is rich in functionality. It creates a DOM tree in memory and allows you to access any part of the document repeatedly and allows you to modify the DOM tree. But it is space inefficient when the document is huge, and it takes a little bit longer to learn how to work with it.</span></b></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>SAMPLE CODE FOR HOW TO PARSING TO XML:</b></span></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 1.5em; text-indent: -0.25in;"></b></div>
<div style="display: inline !important;">
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 1.5em; text-indent: -0.25in;"><br /></b></div>
<br />
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 1.5em; text-indent: -0.25in;"></b></div>
<div style="display: inline !important;">
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 1.5em; text-indent: -0.25in;"><br /></b></div>
<br />
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 1.5em; text-indent: -0.25in;"></b></div>
<div style="display: inline !important;">
<b style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif; line-height: 1.5em; text-indent: -0.25in;">public class domparser extends Activity {</b></div>
<br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 12px; line-height: 18px;"><b></b></span></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> /** Called when the activity is first created. */</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> @Override</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> public void onCreate(Bundle savedInstanceState) {</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> super.onCreate(savedInstanceState);</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> /** Create a new layout to display the view */</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> LinearLayout layout = new LinearLayout(this);</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> layout.setOrientation(1);</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> /** Create a new textview array to display the results */</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> TextView name[];</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> try {</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> URL url = new URL( "your url ");</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> DocumentBuilder db = dbf.newDocumentBuilder();</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> Document doc = db.parse(new InputSource(url.openStream()));</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> doc.getDocumentElement().normalize();</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> NodeList nodeList = doc.getElementsByTagName("results");// chance to your tag name</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> /** Assign textview array lenght by arraylist size */</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> name = new TextView[nodeList.getLength()];</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> for (int i = 0; i < nodeList.getLength(); i++) {</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> Node node = nodeList.item(i);</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> name[i] = new TextView(this);</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> </b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> Element fstElmnt = (Element) node;</b></span><br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b> NodeList nameList = fstElmnt.getElementsByTagName("output");<b style="text-indent: -0.25in;"></b></b></span><br />
<div style="display: inline !important;">
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><b style="text-indent: -0.25in;">// chance to your sub tag name</b></b></span></div>
<br />
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 18px;"><b><span style="font-size: 12px;"> </span> Element nameElement = (Element) nameList.item(0);<br />
nameList = nameElement.getChildNodes();<br />
name[i].setText("results = "<br />
+ ((Node) nameList.item(0)).getNodeValue());<br />
<br />
<br />
layout.addView(name[i]);<br />
<br />
}<br />
} catch (Exception e) {<br />
System.out.println("XML Pasing Excpetion = " + e);<br />
}<br />
/** Set the layout view to display */<br />
setContentView(layout);<br />
}<br />
<br />
<b style="text-indent: -0.25in;"></b><br />
</b></span></span><br />
<div style="display: inline !important;">
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 18px;"><b><b style="text-indent: -0.25in;"><b style="text-indent: -0.25in;"></b></b></b></span></span></div>
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 18px;"><b>
</b></span></span>
<div style="display: inline !important;">
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 18px;"><b><b style="text-indent: -0.25in;"><b style="text-indent: -0.25in;"> </b></b></b></span></span></div>
<span style="color: #666666; font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 18px;"><b>
<br />
<br />
}</b></span></span><br />
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>The xml source code is:</b></span></div>
<div style="color: #666666; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; line-height: 1.5em;">
</div>
<div class="line" style="color: black; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><result></span></span></div>
<div class="collapsible-content" style="color: black; line-height: normal; margin-left: 1em; text-align: -webkit-auto; text-indent: 0px;">
<div class="line">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span class="webkit-html-tag"><output></span><span class="text">successfully received</span><span class="webkit-html-tag"></output></span></span></div>
</div>
<div class="line" style="color: black; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"></result></span></span></div>
<div class="line" style="color: black; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="line" style="color: black; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="line" style="color: black; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="line" style="color: black; font-size: 13px; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="line" style="color: black; font-family: monospace; font-size: 13px; line-height: normal; text-align: -webkit-auto; text-indent: 0px;">
<span class="webkit-html-tag"><br /></span></div>
<br />
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
<div style="color: #666666; font-size: 12px; line-height: 1.5em;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b><br /></b></span></div>
</div>
<div class="MsoNormal" style="color: #666666; font-size: 12px; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal" style="color: #666666; font-size: 12px; line-height: 1.5em; margin-bottom: 12px; margin-left: 0.25in; margin-top: 12px; padding: 0px; text-indent: -0.25in;">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
</div>
<br />
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: white; color: #222222; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div style="background-color: white; color: #222222; font-family: Georgia, 'Times New Roman', serif; font-size: 18px; line-height: 25px; text-align: -webkit-auto;">
<br /></div>
</div>
</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3337248091425613133.post-8731947521259814032012-06-24T23:06:00.002-07:002012-06-24T23:06:25.547-07:00how to use android<div dir="ltr" style="text-align: left;" trbidi="on">
if you want to create new android application.<br />
<br />
I'd take my time and learn Java. I had a look at <a href="http://java.sun.com/docs/books/tutorial/" target="_blank">The Java™ Tutorials</a> the other day and <a href="http://eclipsetutorial.sourceforge.net/" target="_blank">Eclipse And Java Video Tutorials</a> was really simple and easy to understand.</div>Unknownnoreply@blogger.com0