8/10/2019 Cara cara membuat Android 2
1/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 1
A A
D
S II
R
8/10/2019 Cara cara membuat Android 2
2/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 2
C A P P F >> N >> P >> A A
P
E A N, P N & P
N;
8/10/2019 Cara cara membuat Android 2
3/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 3
A A D
C E
C
E: =>
A D
M, C N
8/10/2019 Cara cara membuat Android 2
4/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 4
B E A1) S API(C A API 19)
2) S D S ( 5.1).
5) C . A . C
.
3) G . N .
4)C N
E
1) E
()
2) C
3) C
4) C
8/10/2019 Cara cara membuat Android 2
5/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 5
ANDOID CODING
B & C H
O . ( )
8/10/2019 Cara cara membuat Android 2
6/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 6
A E, B &
8/10/2019 Cara cara membuat Android 2
7/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 7
A C
O .
A ( L 21):17.
A C
O FBHA.
A C()
B
()
A (
C)
C
8/10/2019 Cara cara membuat Android 2
8/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 8
FBHA.1. ..BH;
2. ..A;
3. ..B;
4. ..;
5. ..E;
6. ..;
7. MFBHAA
8. /** C . */
9. @O
10. C(B I)
11. .C(I);
12. C(R..);
13.
14.
15. C( )
16. // 1 .
17. E1= (E) BI(R..1);
18. // ()
19. = 1.().();
20. // 1 .
21. 1= () BI(R..1);
22. // ( )
23. 1.(" N: "+ );
24. 25.
S
C
.
M N(C HN)
8/10/2019 Cara cara membuat Android 2
9/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 9
B C H
HNA.
1. N( )
2. E= (E) BI(R..1);
3. = .().();
4. = F.()
5. = ((* 9) / 5) + 32;
6.
7. 1= () BI(R..1);
8. 1.(+ " C "+
9. + " F.");
10.
/ ,
38.0C 100.4 F.
E:
P 3 C
8/10/2019 Cara cara membuat Android 2
10/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 10
:
M C
E: M C
1. C( )
2. E1= (E)BI(R..1);
3. 1= 1.().();
4. I1= I.(1)
5. E2= (E)
BI(R..2);6. 2= 2.().();
7. I2= I.(2)
8. = I1*I2;
9. = ()BI(R..2);
10. .("R : "+ );
11.
8/10/2019 Cara cara membuat Android 2
11/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 11
E:
B C
DUPLICATING & IMPORTING
AN ANDROID PROJECT
8/10/2019 Cara cara membuat Android 2
12/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 12
D A P
S C &
P ( E)
H
CC (C)
C (P)
E
C A
E: F > I
C A >E A
C I N > B >
OK > > F
8/10/2019 Cara cara membuat Android 2
13/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 13
U B S
26
The ifstatement has the following syntax:
if ( condition) {
statement(s);}
if is a Javais a Javais a Javais a Java
reserved wordreserved wordreserved wordreserved word
TheTheTheThe conditionmust be amust be amust be amust be a
booleanbooleanbooleanboolean expression. It mustexpression. It mustexpression. It mustexpression. It must
evaluate to either true or false.evaluate to either true or false.evaluate to either true or false.evaluate to either true or false.
If theIf theIf theIf the conditionis true, theis true, theis true, theis true, the statement(s) is executed.is executed.is executed.is executed.
If it is false, theIf it is false, theIf it is false, theIf it is false, the statement(s) isisisis skipped.skipped.skipped.skipped.
8/10/2019 Cara cara membuat Android 2
14/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 14
27
O A condition often uses one of Java's equality operators or
relational operators, which all return boolean results:
==
!=
<
>
=
: O E N
8/10/2019 Cara cara membuat Android 2
15/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 15
: O E N
1. E = (E) BI(R..1);
2. = .().();
3. = I.()
4. = "N ";
5. (%2 == 0) // (/2*2 == )
6. = "EEN";
7.
8. = "ODD";
9.
10. = () BI(R..2);
11. .(" "+ );
E: P F?
R
D .
50 & .
8/10/2019 Cara cara membuat Android 2
16/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 16
: B C & I
H://.
IDEO
L & R
8/10/2019 Cara cara membuat Android 2
17/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 17
1. C(B I)
2. .C(I);
3. C(R..);
4.
5. = "://../S/M/HTTP/H264/ TM/H2642T4480320.4";
6. = .();
7. = () BI(R..1);
8.
9. MC = MC();
10. .MC();11. .RI();
12. .F();
13. .OPL(OL()
14. PB=(PB) BI(R..B1);
15.
16. (M )
17. . (.E);// C
18. .A();
19. .();
20.
21. );
22.
8/10/2019 Cara cara membuat Android 2
18/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 18
1. C(B I)
2. .C(I);
3. C(R..);
4.
5. = "://..//3073/.4";
6. = .();
7. = () BI(R..1);
8.
9. MC = MC();
10. .MC();
11. .RI();
12. .F();
13. .OPL(OL()
14. PB=(PB) BI(R..B1);
15.
16. (M ) 17. . (.E);// C
18. .A();
19. .();
20.
21. );
22.
8/10/2019 Cara cara membuat Android 2
19/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 19
L 1. C(B I)
2. .C(I);
3. C(R..);
4. = .(".://"+A().()+"/"+..);
5. = ()BI(R..1);
6. MC = MC();7. .MC();
8. .RI();
9. .();
10.
PLA AN ADIO
1. MA A
2. M ;
3. @O
4. C(B I)
5. .C(I);
6. C(R..);
7. = M();
8.
9.
10. ( )
11. = MP.(A.,
..)
12. .();
13.
14.
M P .
8/10/2019 Cara cara membuat Android 2
20/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 20
ALKING ANDOID
A I!
:
1. MAAOIL
2. ;
3.
4. @O5. C(B
I)
6. .C(I);
7. C(R..);
8. = (, );
9.
8/10/2019 Cara cara membuat Android 2
21/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 21
:
10. @O
11. I(0)
12. // ODOA
13. .L(L.);
14. .R(());
15. .(,.EEF, );
16.
17.
OCH HANDLING
8/10/2019 Cara cara membuat Android 2
22/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 22
: A LC A
/
E.
E: S > O/I
T
A .
T.T(, O T", T.LENGTHSHORT).();
T : T T
H T
..T;
I OA IDGE
8/10/2019 Cara cara membuat Android 2
23/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 23
: , M & L E
: E
1. @O
2. E(ME )
3. = .A();
4. (==ME.)
5. .(AC(),"... ", .E).();
6.
7. ;
8.
8/10/2019 Cara cara membuat Android 2
24/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 24
: D E
1. GAA
2. 1, 2;
3. 1, 2;
4. @O
5. C(BI)
6. .C(I);7. C(R..);
8.
: D E
9. @O
10. E(ME )
11. = .A();
12. ()
13. ME.
14. 1= .();15. 1= .();
16. ;
17. ME.
18. 2= .();
19. 2= .();
8/10/2019 Cara cara membuat Android 2
25/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 25
: D E20. //
21. (1< 2) // (21>50)
22. .(, " ",.E).();
23.
24. //
25. (1> 2) // (12> 50)
26. .(, " ",.E).();
27.
28. // P D
29. (1< 2)
30. .(, " ",.E).();
31.
: D E
32. // D P
33. (1> 2)
34. .(," ",.E).();
35.
36. ; // MOE
37.
38. ;
39.
8/10/2019 Cara cara membuat Android 2
26/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 26
E
,
.
,
.
OPEN ANOHE LAO
8/10/2019 Cara cara membuat Android 2
27/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 27
O A L
T
C().
: O A L
8/10/2019 Cara cara membuat Android 2
28/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 28
: O A L
1. MAA
2. @O
3. C(B I)
4. .C(I);
5. C(R..);
6.
7. OL2( )
8. C(..)
9.
10.
E: O A L
T BACK
(
).
8/10/2019 Cara cara membuat Android 2
29/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 29
E: O A L
1. OL2( )
2. C(R..);
3.
4. HBACK( )
5. C(R..);
6.
E: O A L
8/10/2019 Cara cara membuat Android 2
30/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 30
E: O A L
( )
1. @O
2. E(ME )
3. // ODOA
4. = .A();
5. (==ME.)
6. C(R..);
7.
8. ;
9.
ACION BA MEN
8/10/2019 Cara cara membuat Android 2
31/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 31
: C A B M
: C A B M
2 :
L
. ( > ).
O
OI(MI )
S H
L D A B
8/10/2019 Cara cara membuat Android 2
32/94
8/10/2019 Cara cara membuat Android 2
33/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 33
: C A B M15.
21.
27.
33.
: C A B M
.: ( & OI)
1. @O
2. OI(MI )
3. // H .
4. // H/ ,
5. // AM..
6. = .II();
7. ( == ..)
8. C(R..);
9.
10. ( == ..2)
11. C(R..2);
12.
8/10/2019 Cara cara membuat Android 2
34/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 34
: C A B M .: ( & OI)
13. ( == ..)
14. = MP.(AC(),..);
15. .();
16.
17. ( == ..)
18. .();
19. 20. ( == ..)
21. C(R..);
22.
23. .OI();
24.
DPLICAING & IMPOING
AN ANDOID POJEC
8/10/2019 Cara cara membuat Android 2
35/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 35
D A P
S C &
P ( E)
H
CC (C)
C (P)
E
C A
E: F > I
C A >E A
C I N > B >
OK > > F
8/10/2019 Cara cara membuat Android 2
36/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 36
D I
:
D I
8/10/2019 Cara cara membuat Android 2
37/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 37
A 2.3.3
8/10/2019 Cara cara membuat Android 2
38/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 38
1. HD( )
2. = "://.//./"+
3. "/////2013/ANDROID.";
4.
5. .(AC(), "...",
.E).();
6. B R = BF.(()
7. L().C());
8. I = (I) BI(R..1);
9. .IB(R);
10. .(AC(), " D...",
.E).();
11. (E )
12.
8/10/2019 Cara cara membuat Android 2
39/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 39
N
E API19
: D
A
8/10/2019 Cara cara membuat Android 2
40/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 40
: D A
1. MAABA
2. ="://.//./"+"/////2013/ANDROID." ;
3. @O
4. C(B I)
5. .C(I);
6. C(R..);
7.
8. HD( ) 9. D().();10. .(AC(), " ...",
.E).();
11.
: D A
12. DA
13. @O
14. B IB(... 0)
15. B R = ;16.
17. R =BF.(()
().C());
18. (E )
19. ;
20.
8/10/2019 Cara cara membuat Android 2
41/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 41
: D A
21. E(B)
22. .(AC()," ...",
.E).();
23. I = (I)BI(R..1);
24. .IB();
25.
26.
27.
(2014)
T/AT
8/10/2019 Cara cara membuat Android 2
42/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 42
A?
When an Android application is first started, the runtime system
creates a single thread in which all application components will run
This thread is referred to as the main thread(also known as UI thread,
since it modifies the user interface and handles input events)
All code of an Android application (incl. additional components) runs in the
main thread and every statement is executed after each other
If you perform a long lasting operation(e.g accessing data from the Internet)
the application is blocked until the corresponding operation has finished.
A?
Android enforces a worst case reaction time of applications.
If an activity does not react within 5 seconds to user input,
the Android system displays an Application not responding (ANR) dialog.
From this dialog the user can choose to stop the application
NOTE!
8/10/2019 Cara cara membuat Android 2
43/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 43
LOGO
Android AsynTask
Enables proper and easy use of the UI thread. Thisclass allows to perform background operations and
publish results on the UI thread without having to
manipulate threads and/or handlers.
Introduction
AsyncTask is a generic class, it uses 3 types:
AsyncTask.
Params the input. What you pass to the
AsyncTask
Progress if you have any updates, passed toonProgressUpdate()
Result the output. What returns doInBackground()
Example:private class MyTask extends AsyncTask { }
OR
private class MyTask2 extends AsyncTask { }
8/10/2019 Cara cara membuat Android 2
44/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 44
Introduction
The most common methods you will need to
implement (overrides) are these:
1. onPreExecute() called on the UI thread
before the thread starts running.
2. doInBackground(Params)put all the code
you want the application to perform in
background.
3. onProgressUpdate() - called when you invokepublishProgress() in the doInBackground().
4. onPostExecute(Result) called after the
background thread finishes.
Example
Hello World! Become
Downloading
Then progressing
values will appear
Final msg, All Done!
8/10/2019 Cara cara membuat Android 2
45/94
8/10/2019 Cara cara membuat Android 2
46/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 46
Example
33. @O
34. (I... )
35. .();
36. .("P : "+ 0);
37.
38. @O
39. E( )
40. .E();
41. .();
42.
43.
44.
Input from 2nd paramof the AsynTask cls
Input from 3rd param
of the AsynTask cls
Summary
1. A( )
2. M().("://.." );
3.
4. MA
5. E()
6.
7. IB(... )
8. P();
9. "A D!";
10.
11. (I... )
12.
13. E( )
14.
15.
8/10/2019 Cara cara membuat Android 2
47/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 47
Summary
1. A( )
2. M().();
3.
4. MA
5. E()
6.
7. IB(... )
8. P();
9. ;
10.
11. (I... )
12.
13. // E( )
14. // NO IMPLEMENED
15.
D C:
O 1. MA ABA
2. = "://.//./"
3.
4. @O
5. C(B I)
6.
7. HD( )
8. D().();
9.
10. D A
11. @O
12. BIB(... 0)
13. ;
14.
15. E(B)
16.
17.
1
2
3
8/10/2019 Cara cara membuat Android 2
48/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 48
D C:
A I1. MA ABA
2. = "://.//./"
3.
4. @O
5. C(B I)
6.
7. HD( )
8. D().();
9.
10. D A
11. @O
12. BIB(... 0)
13. ;
14.
15. E(B)
16.
17.
C ( PE?
T.((), " ",
T.)()
I = (I)
BI(R..)
.IB();
D C:
A I1. MA ABA
2. = "://.//./"
3.
4. @O
5. C(B I)
6.
7. HD( )
8. D().();
9. .(AC(), " ...",
10. .LENGHLONG).();
11.
12. D A
13. @O
14. BIB(... 0)
15. ;
16.
17.
C A
?
T.((), "
",
T.)()
8/10/2019 Cara cara membuat Android 2
49/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 49
D C:
A I ( )P
AT ,
,
O/I
M
D C:
A I ( 1 )
1. HD( )
2. = ://.//./ +"/////2013/ANDROID." ;
3. D().();4.
5. DA
6. @O
7. B IB(... 0) 8. B R = ;
9.
10. R = BF.(()
(00).())
8/10/2019 Cara cara membuat Android 2
50/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 50
D C:
A I ( 1
)1. DA
2. @O
3. B IB(... 0)
4.
5. F= L(00).C().CL();
6. (F);
7. R = BF.(()
(00).())
8. (E )
9. @O
10. (I... )
11. .();
12. .(AC(), " =
"+0, .E).();
13.
(2014)
EA: DONLOAD IMAGE FOM
HE INENE
8/10/2019 Cara cara membuat Android 2
51/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 51
I A P
Before your application can access the Internet, it needs
to be
granted permission for Internet access..
Add this in the AndroidManifest.xml:
B T
Starting with Android 3.0 (Honeycomb) you may not
perform
network operations on your main UI thread
This will cause a NetworkOnMainThreadException
In order to solve this, you need to use background
thread:
Handler
or
AsyncTask
8/10/2019 Cara cara membuat Android 2
52/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 52
D I: E
Try to do this application:
(Use AsyncTask for the downloading task)
Downloading the image must be performed as
a background task (NEVER in the main UI
thread)
Therefore, in this example, we will use
AsyncTask for the downloading job.
D I: E
U : ://..//0202/B.
8/10/2019 Cara cara membuat Android 2
53/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 53
1. Create the main layout (xml) for your
Activity. It should have:
A TextView for the title
A ProgressBar (initially invisible) to show
progress
A TextView to display % progress
An ImageView to display the downloaded
image(set background color to black)
An EditText to enter the image URL
A Button to start the downloading
D I: E
2. In your Activity class,
get handles to the all of the views used (call findViewById( ))
inside the onCreate() method
define the button onclick method. In this method:
Get the String from the url address TextView
Create the AsyncTask object & call its execute() method bypassing the url address(String) as its parameter
public void download(View v) {
String url = etUrl.getText().toString().trim();
new ImageDownloader().execute(url);}
*ImageDownloaderis the name of
our AsyncTask
D I: E
8/10/2019 Cara cara membuat Android 2
54/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 54
3. Create a subclass of AsyncTask names ImageDownloader, as a
private inner class inside your Activity class
- Use the three generic types as specified:
private class ImageDownloader extends
AsyncTask {
}
D I: E
4. Override all the fourmethods in your AsyncTask , starting with the
onPreExecute() method.
- This is for initialising purpose
@Override
protected void onPreExecute() {progress = 0; //declare this int variable as global in your AsyncTaskpb.setVisibility(View.VISIBLE);
Toast.makeText(LoadImageAsyncTaskActivity.this,
"starting download", Toast.LENGTH_SHORT).show();
super.onPreExecute();
}
onPreExecute() method:
D I: E
8/10/2019 Cara cara membuat Android 2
55/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 55
5. Override the doInBackground () method.
- This is for the background task done by the background thread
@Override
protected Bitmap doInBackground(String... urls) {
Bitmap bmp = loadImageFromNetwork(urls[0]); //do the loading taskwhile (progress < 100) {
progress += 1;
publishProgress(progress); //update progress to UI thread
SystemClock.sleep(100); //to slowdown the system
}
return bmp;}
doInBackground() method:
D I: E
6. Override the onProgressUpdate () method.
- This is to show download progress in the ProgressBar and
TextView on main UI thread
@Override
protected void onProgressUpdate(Integer... values) {
pb.setProgress(values[0]);
percent.setText(values[0] + "%");
}
onProgressUpdate() method:
D I: E
8/10/2019 Cara cara membuat Android 2
56/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 56
D I E
7. Override the onPostExecute () method.
- This is to display the result (image) in the ImageView &
a message that download has completed (using Toast)
@Override
protected void onPostExecute(Bitmap result) {
img.setImageBitmap(result);Toast.makeText(LoadImageAsyncTaskActivity.this,
"download complete", Toast.LENGTH_SHORT).show();
}
onPostExecute() method:
8. Define the loadImageFromNetwork () method.
- This method do the actual work of loading the image from the
given url address
private Bitmap loadImageFromNetwork(String url) {
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
// URL urlObj = new URL(url);
// InputStream in = (InputStream) urlObj.getContent();//Bitmap bitmap = BitmapFactory.decodeStream(in);
return bitmap;
} catch (Exception e) {
e.printStackTrace();Log.d("getBmpFromUrl error: ", e.getMessage().toString());
return null;
}
}
loadImageFromNetwork() method:
D I: E
8/10/2019 Cara cara membuat Android 2
57/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 57
9. Add permission for Internet access in your manifest file.
8/10/2019 Cara cara membuat Android 2
58/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 58
(2014)
: D F
(2014)
: D F
1. F( )
2. I = ;
3. = "";
4. = "://./100";
5. = ()
BI(R..1);
6. .("RL: "+ );
8/10/2019 Cara cara membuat Android 2
59/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 59
(2014)
: D F7.
8. // F
9. = DHC().(
HG()).E().C();
10. // BR
11. BR = B(
I());
12. //R R
13. ( = .L(); != ; =
.L())
14. += ;15. .();
16. (E )
17. E = (E) BI(R..1);
18. .();
(2014)
8/10/2019 Cara cara membuat Android 2
60/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 60
(2014)
: D F
( )
1. MAABA
2. I= ;
3. = "";
4. = "://./100";
5. @O
6. C(B I)
7. .C(I);
8. C(R..);
9.
(2014)
: D F
( )
10. F( )
11. = () BI(R..1);
12. .("RL: "+ );
13. = F();
14. E = (E) BI(R..1);
15. .();
16.
8/10/2019 Cara cara membuat Android 2
61/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 61
(2014)
: D F
( )
17. F ( )
18.
19. = DHC().(
HG()).E().C();
20. BR = B(
I());
21. ( = .L(); != ; =
.L())
22. += ;
23. .();
24. (E )
25.L.("", .());
26.
27.;
28.
(2014)
H & H E
8/10/2019 Cara cara membuat Android 2
62/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 62
(2014)
H & H E
1.
(2014)
H & H E
1. F( )
2. = () BI(R..1);
3. .("RL: "+ );
4. = F();
5. E = (E) BI(R..1);6. .(.)
7. .();
8.
8/10/2019 Cara cara membuat Android 2
63/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 63
(2014)
:
D F A
(2014)
:
D F A
1. F( )
2. = () BI(R..1);
3. .("RL: "+ );
4. MDF().();5.
6. MDFA
7. @O
8. IB(... )
9. // ODOA
10. = F();
11. ;
12.
8/10/2019 Cara cara membuat Android 2
64/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 64
(2014)
:
D F A
13. @O
14. E( )
15. // ODOA
16. .E();
17. E = (E) BI(R..1);
18. .(.BE);
19. .(R);
20.
(2014)
: D F
P ( )
8/10/2019 Cara cara membuat Android 2
65/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 65
(2014)
: D F
P ( )
1. F( )
2. = () BI(R..1);
3. MDF().();
4.
5. MDFA
(2014)
: D F
P ( )
6. @O
7. IB(... ) 8. = "";
9.
10. // F
11. = DHC().(HG()).E().C();
12. // BR
13. BR = B(I());14. //R R
15. ( = .L(); != ; = .L())
16. += ;
17. ();18. 19. .();
20. (E )
21. L.("", .());
22.
23. ;
24.
8/10/2019 Cara cara membuat Android 2
66/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 66
(2014)
: D F
P ( )
25.@O
26. (... )
27.// ODOA
28. .();
29. .("R : "+
0);
30.
(2014)
:
D P F
8/10/2019 Cara cara membuat Android 2
67/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 67
(2014)
:
D P F
S
(
ET).
(2014)
:
D P F
1. @O
2. E(
)
3. // ODOA
4. .E();
5. = ()
BI(R..1);
6. .D(R, "/", );
7.
8/10/2019 Cara cara membuat Android 2
68/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 68
(2014)
: D P F
D L
(2014)
: D P F
D L
1. F( )
2. E = (E)BI(R..1);
3. RL=.().().();
4. = () BI(R..1);
5. .("RL: "+ RL);
6. MDF().(L);7.
8. MDFA
8/10/2019 Cara cara membuat Android 2
69/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 69
(2014)
: D P F
D L9. @O
10. IB(... ) 11. // ODOA
12. = "";
13. L = 0;14.
15. // F
16. = DHC().(
HG(L)).E().C();17. // BR
18. BR = B(I());
19. //R R
20. ( = .L(); != ; = .L())
21. += ;
22. //P();23.
24. .();
25. (E )
26. L.("", .());
27.
28. ;29.
(2014)
A
8/10/2019 Cara cara membuat Android 2
70/94
8/10/2019 Cara cara membuat Android 2
71/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 71
(2014)
A D :
A
(2014)
A D :
A
8/10/2019 Cara cara membuat Android 2
72/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 72
(2014)
A D :
A A
(2014)
JON (JS O N)
ML
8/10/2019 Cara cara membuat Android 2
73/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 73
(2014)
JON (JS O
N)
() JSON
() JSON
A JSON . P / JSON
E , .
(2014)
JON P
3 :
D JSON
P
D ()
8/10/2019 Cara cara membuat Android 2
74/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 74
(2014)
JON P
1: D JON F
F
,
JSON URL, ..
="://.../
/.";
(2014)
JON P E
1: D JON F
8/10/2019 Cara cara membuat Android 2
75/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 75
(2014)
JON P
2: P JON F
(2014)
JON P
2: P JON F
F JSON ,
JSONO JSON . I
:
JONO = JONO(JON);
A JSON /
:
JONO = .JONO("");
C = .("");
8/10/2019 Cara cara membuat Android 2
76/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 76
(2014)
JON P
2: P JON F1. JON( JON)
2. // ODOA
3. JONO O;
4. D, ;
5.
6. O = JONO(JON);
7. D = O.("");
8. = O.("");
9. .(AC(),
" D: "+D+" "+,.E).();
10. (JONE )
11.
(2014)
JON P
3: D O/D
8/10/2019 Cara cara membuat Android 2
77/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 77
(2014)
JON P
3: D O/D
1. JONO O;
2. D="", ="";
3.
4. O = JONO(JON);
5. D = O.("");
6. = O.("");
7. (JONE )
8. D = ()BI(R..3);
9. =()BI(R..4);
10. D.(" D: "+D);
11. .(" : "+);
(2014)
JON P
P JON F A O
8/10/2019 Cara cara membuat Android 2
78/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 78
(2014)
JON P
P JON F A O
1. JON( JON)
2. // ODOA
3. JONO O;
4. M="", ="",
="";
5. O = " M
:";
6.
7. O = JONO(JON);
(2014)
P JON F
A O
8. // G JON A
9. JONA A =
O.JONA
("");
10. // A 11. ( = 0; 0) {
byte[] b = new byte[4096];n = in.read(b);
if (n > 0)
out.append(new String(b, 0, n));}
return out.toString();
}
getResultFromEntity() method:
E : A S C R A
8. Add permission for Internet access in your manifest file.
8/10/2019 Cara cara membuat Android 2
89/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 89
I
, /.
I II
O .
T
, .
T OAP E.
A SOAP ,
8/10/2019 Cara cara membuat Android 2
90/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 90
I (E)
REST ( REST) S .
M REST, T, F, F, .
REST , , HTTP.
A JSON(JS O N) ML.
JON
S JSON :
"" :
"": "1234",
"" : "","" : ""
I JSON :
"" :
"": "1234",
"" : "","" : ""
..JSONE;
..JSONO;
8/10/2019 Cara cara membuat Android 2
91/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 91
JON II1. S ;
2. S ;
3. S ;
4. S S = """ : "": "1234","" :
A","" : A S"";
5.
6. JSONO O= JSONO(S);
7. JSONO O = O.JSONO("");
8. = O.S("");
9. = O.S("");
10. = O.S("");
11.
12. (JSONE )
13.
P JSON
The results from List operation is in JSON format.
We have to parse the JSON formatted massage to extract the data inside it
e.g. how to obtain only the names and phone numbers from the message
8/10/2019 Cara cara membuat Android 2
92/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 92
P JSON
To parse JSON message, youll need these Java classes from
org.json package:
JSONObject
JSONArray
Also need the StringBuilder to append the string, representing
each of the JSON object, extracted from JSON message
P JSON
1. We need to do the parsing in the AsyncTask onPostExecute method:
(you can modify this method from the last example)
protected void onPostExecute(String result)
Notice that this method receives a string parameter, result, which contain
the JSON message that we are going to process. Also declare the
StringBuilder:StringBuilder contactResult = new StringBuilder();
2. The JSON processing methods can throw exceptions, so add try and
catch blocks next:try {
}catch (Exception e) {
et.setText(Something went wrong!");
e.printStackTrace();
}
8/10/2019 Cara cara membuat Android 2
93/94
A A D (S II) 35 N 2014
ASMATT (1207@..) 93
P JSON
3. Inside the try block, create a JSONObject, passing the JSON result
as the parameter:
JSONObject resultObject = new JSONObject(result ) ;
4. We need to retrieve this contact array, using its name: Contacts. Get
the Contacts array from the JSON Object:
JSONArray contactArray = resultObject.getJSONArray("Contacts");
P JSON
5. After fetching the contact array, add a for loop to iterate through the
contacts:
for (int t=0; t
8/10/2019 Cara cara membuat Android 2
94/94
A A D (S II) 35 N 2014
P JSON
7. Now retrieve the person name from this object, appending it to the
String Builder :
contactResult.append(contactObject.getString("name")+ ": ");
8. Next, retrieve the phone number from the object, also appending it to
the String Builder and ended with a new line character:
contactResult.append(contactObject.getString("telNo")+ "\n");
P JSON
9. Now move to after the catch block. If the processing has worked, we
display the result (convert the StringBuilder to String) in the EditText ,
otherwise we display an error message::
if(contactResult length()>0)