-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathpiccall.html
More file actions
566 lines (566 loc) · 16.6 KB
/
Copy pathpiccall.html
File metadata and controls
566 lines (566 loc) · 16.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta content="App Inventor for Android" name="description" />
<meta content="Android, Blocks App Inventor, Mobile, Phone, IDE" name="keywords" />
<title>
PicCall - App Inventor for Android
</title>
<link href="/static/images/appinventor-16.png" rel="SHORTCUT ICON" type="image/ico" />
<link href="/static/images/appinventor-16.png" rel="icon" type="image/png" />
<link href="/static/css/appinventor.css" rel="stylesheet" />
<script src="http://www.google.com/js/gweb/analytics/autotrack.js">
</script>
<script>
var tracker = new gweb.analytics.AutoTrack({
profile: 'UA-5856106-2'
});
</script>
<script language = "JavaScript" src="/static/scripts/HeaderAndFooter.js"></script>
<style>
img.c3 {border-width:0}
img.c2 {padding: 10px}
div.c1 {clear:both;}
</style>
</head>
<body>
<script language = "JavaScript">createHeader('<div id="navigation-breadcrumb"> <a href="/learn/">Learn</a> > <a href="/learn/tutorials/">Tutorials</a> > PicCall > ');</script><br>
<div id="aiac">
<div class="main-container">
<div class="customhr customhr-gray">
</div>
<div class="content">
<div class="content-body">
<div class="learn-page">
<h1>
PicCall
</h1>
<img align="right" alt="" class="c2" src="PicCallAssets/PicCallEmulator.png" width="200" />
<p>
<em>
PicCall
</em>
shows how you can use App Inventor to make apps that do actual
phone things, like calling friends.
</p>
This tutorial assumes that you have completed the
<a href="/learn/setup/index.html">
Set Up
</a>
process.
<h2>
Before starting
</h2>
<p>
To run
<em>
PicCall
</em>
, your phone must be set up and activated for making phone
calls. If it isn't, you can still build
<em>
PicCall
</em>
for practice, but the
phone won't actually make the calls.
</p>
<blockquote class="notice">
Warning: PicCall does not work on all Android phones in the current implementation
of App Inventor: you'll get an error notice on some phones when you try to pick a
phone number. Also, you won't see all your contacts — only those created from
Gmail. These limitations will be removed in the future.
</blockquote>
In this tutorial, unlike
<em>
HelloPurr
</em>
, you'll give names to
components, rather than just using the default names that App Inventor provides (like
"Button1"). Using meaningful names is good programming practice: it helps you keep
your programs straight in your own mind, and it helps others understand your
programs.
<p>
Your phone should also contain a few contacts with pictures. You can use the
Contacts app to save pictures for your contacts. You can also click on Contacts in
your Gmail account on your computer and add pictures there.
</p>
Make sure your computer and your phone are set up to use App Inventor, and browse
to the App Inventor Web site at
<a href="http://appinventor.mit.edu">
http://appinventor.mit.edu
</a>
. Start a new
project in the
<em>
Designer
</em>
window. Name it
<em>
PicCall
</em>
and change the
screen
<span class="ButtonText">
Title
</span>
to
<em>
PicCall
</em>
. Open the Blocks
Editor, click
<span class="ButtonText">
Connect to Phone
</span>
, and check that the
phone has started the App Inventor app.
<br clear="all" />
<h2>
Getting started
</h2>
<p>
Start out just like in
<em>
HelloPurr
</em>
by placing a button on the screen. Make
the button 150 pixels wide and 150 pixels high. Set button's
<span class="ButtonText">
Image
</span>
to a picture. You may as well use the picture of the
kitty if it's handy — you'll be changing the picture soon. Set the
<span class="ButtonText">
Text
</span>
of the button to "Press to Call", although you'll be
changing that soon, as well.
</p>
Change the name of the
<span class="ButtonText">
Button
</span>
component to
<span class="ButtonText">
TopButton
</span>
(You'll make a
<span class="ButtonText">
BottomButton
</span>
later in the tutorial.) To change a component's
<span class="ButtonText">
name
</span>
, click the
<em>
Rename
</em>
button in the
Components panel and enter the new name.
<blockquote class="notice">
In this tutorial, unlike
<em>
HelloPurr
</em>
, you'll give names to components,
rather than just using the default names that App Inventor provides (like
"Button1"). Using meaningful names is good programming practice: it helps you keep
your programs straight in your own mind, and it helps others understand your
programs. Don't confuse the
<span class="ButtonText">
name
</span>
of a component
with the
<span class="ButtonText">
text
</span>
of a component. The
<span class="ButtonText">
text
</span>
is what appears on the screen. The
<span class="ButtonText">
name
</span>
is the name your program uses to refer to the component.
You'll see the name in the
<span class="ButtonText">
Components
</span>
structure
list in the
<span class="ButtonText">
Designer
</span>
and on the drawers in the
Blocks editor.
</blockquote>
<h2>
Making phone calls
</h2>
<p>
In
<em>
HelloPurr
</em>
, you made the phone play a sound when the button was clicked.
<em>
PicCall
</em>
in almost the same, except that instead of playing a sound, the
phone makes a call.
</p>
App Inventor's
<span class="ButtonText">
PhoneCall
</span>
component makes phone
calls. You can find
<span class="ButtonText">
PhoneCall
</span>
in the
<em>
Social
</em>
section of the
<em>
Palette
</em>
. Open that section and drag out a
<span class="ButtonText">
PhoneCall
</span>
into the viewer. It will go into the Non-visible
components area. Name it
<span class="ButtonText">
TopCall
</span>
. The
<span class="ButtonText">
PhoneCall
</span>
's
<span class="ButtonText">
PhoneNumber
</span>
property
determines the number to call. Set that to some 10-digit phone number you'd like to
call. Here's how the
<span class="ButtonText">
Designer
</span>
should look:
<div class="imagecontainer">
<img alt="" src="PicCallAssets/PicCallDesigner.png" width="800" />
</div>
Now switch to the Blocks Editor and pull out the
<span class="Block">
when
TopButton.Click do
</span>
block. In the
<span class="ButtonText">
do
</span>
slot,
place a
<span class="Ball">
call TopCall.MakePhoneCall
</span>
block from the
<span class="ButtonText">
TopPhoneCall
</span>
drawer, so that the event handler looks
like this:
<div class="imagecontainer">
<img alt="" height="102" src="PicCallAssets/PicCallWhenClick.png" width="243" />
</div>
Go ahead and test what you have so far on the phone: Press the button and make
the call. You could package this up as an app right now. It would be a pretty limited
app, always calling the same fixed number, some people might find that useful.
<h2>
Phone contact information
</h2>
<p>
In addition to making phone calls, App Inventor apps can also get information from
the phone's contact list. You do this with the
<span class="ButtonText">
PhoneNumberPicker
</span>
component.
</p>
Pull out a
<span class="ButtonText">
PhoneNumberPicker
</span>
component from the
<em>
Social
</em>
section of the
<em>
Palette
</em>
, place it under
<span class="ButtonText">
TopButton
</span>
and rename it to
<span class="ButtonText">
TopPick
</span>
. A
<span class="ButtonText">
PhoneNumberPicker
</span>
a
kind of button: when you press it, it brings up your phone contacts list and lets you
pick someone. Change the name of the
<span class="ButtonText">
PhoneNumberPicker
</span>
to
<span class="ButtonText">
TopPick
</span>
, and
change its
<span class="ButtonText">
Text
</span>
to "Press to pick a number to call".
Try it by pressing the picker on your phone: you should see your contacts come up,
and you can pick one. Nothing will happen after you pick, because you haven't yet
told the components to do anything. You'll do that next.
<h2>
Using the picker
</h2>
<p>
Switch to the Blocks window and open the drawer for
<span class="ButtonText">
TopPick
</span>
. Drag out the
<span class="Block">
when
TopPick.AfterPicking do
</span>
block. This lets you define an event handler that
says what to do after you've picked a number from your contacts.
</p>
Now open the
<span class="ButtonText">
TopCall
</span>
drawer and drag out
<span class="Block">
set TopCall.PhoneNumber to
</span>
and fit it into the slot in the
<span class="Block">
when TopPick.AfterPicking do
</span>
block. Now drag out
<span class="Block">
TopPick.PhoneNumber
</span>
from the
<span class="ButtonText">
TopPick
</span>
drawer and plug it into the empty socket. Here's how your
event handler should look:
<div class="imagecontainer">
<img alt="" height="108" src="PicCallAssets/PicCallAfterPicking.png" width="405" />
</div>
Try it on the phone: Press the picker, choose a contact and a phone number.
Then press the phone call button to make the call. Add a command to the event handler
to set
<span class="ButtonText">
TopButton
</span>
's
<span class="ButtonText">
Text
</span>
property to
<span class="ButtonText">
TopPick.PhoneNumber
</span>
:
<div class="imagecontainer">
<img alt="" height="144" src="PicCallAssets/PicCallAfterPicking2.png" width="408" />
</div>
<h2>
Pictures
</h2>
<p>
If you have a picture stored with your contacts, you can make the button show that
along with the phone number, rather than always using the picture of the kitty. To
do this, add an command to the event handler, to set the
<span class="ButtonText">
Image
</span>
property of
<span class="ButtonText">
TopButton
</span>
to
be the the
<span class="ButtonText">
Picture
</span>
property of
<span class="ButtonText">
TopPick
</span>
:
</p>
<div class="imagecontainer">
<img alt="" height="187" src="PicCallAssets/PicCallAfterPicking3.png" width="410" />
</div>
<blockquote class="notice">
<span class="ButtonText">
PhoneNumberPicker
</span>
has two properties that are easy
to confuse:
<span class="ButtonText">
Picture
</span>
and
<span class="ButtonText">
Image
</span>
.
<span class="ButtonText">
Picture
</span>
is the picture
associated with the contact that's picked.
<span class="ButtonText">
Image
</span>
is
the image of the
<span class="ButtonText">
PhoneNumberPicker
</span>
component as it
appears in the
<span class="ButtonText">
Designer
</span>
and on the phone.
</blockquote>
<h2>
Enhancements
</h2>
<p>
Here are some variations for you to try:
</p>
<ul>
<li>
Add a second button,
<span class="ButtonText">
BottomButton
</span>
and a second
PhoneNumberPicker, so that your app gives you the choice of two numbers.
</li>
<li>
Add a label with instructions on how to use the app.
</li>
<li>
Show the name of the person being called in addition to the phone number. Use
an extra label to show the additional information.
</li>
</ul>
<h2>
Using PicCall
</h2>
<p>
You can package
<em>
PicCall
</em>
and download it to the phone so you can use it
when you're not connected to the computer. But there's a big limitation: Every time
you restart
<em>
PicCall
</em>
, it starts fresh and does not remember what you picked
last time. Later, we'll see how to use the
<span class="ButtonText">
TinyDB
</span>
component to create apps that can remember information from one time to the next.
Such information is called
<i>
persistent data
</i>
.
</p>
<h2>
Review
</h2>
Here are the key ideas covered in this tutorial:
<ul>
<li>
<p>
You can name components by means of the Rename button.
</p>
</li>
<li>
<p>
App Inventor has components that can use information stored on the phone. The
<span class="ButtonText">
PhoneNumberPicker
</span>
can get phone numbers and
pictures for your contacts, and
<span class="ButtonText">
PhoneCall
</span>
can
make calls.
</p>
</li>
</ul>
<blockquote class="Dogfooding">
<b>
Tip:
</b>
The list that comes up when you run the phone number picker does not
show the pictures associated with your contacts, on some Android systems. Even
though the image isn't shown, the "Picture" property will still return a picture
that will show up when you run the app, provided that the phone has a picture for
that contact.
</blockquote>
</div>
</div>
</div>
<div class="footer">
<script language = "JavaScript">createFooter();</script><br>
<div class="footer-lastupdate">
<script>
if (document.lastModified != '') {
var m = "Page last updated: " + document.lastModified;
var p = m.length-8;
document.writeln("<center>");
document.write(m.substring(p, 0));
document.writeln("<\/center>");
}
</script>
</div>
</div>
</div>
</div>
</body>
</html>