In
ApiDemos,
Here’s how I found the names of the package and the activity class
I passed to the
constructor
for
ComponentName
The
<manifest>
element in the ApiDemos
AndroidManifest.xml
file contains the following attribute.
package="com.example.android.apis"
This
<manifest>
element contains an
<application>
element that contains hundreds of
<activity>
elements.
One of them
is
<activity android:name=".graphics.GLES20Activity" android:label="Graphics/OpenGL ES/OpenGL ES 2.0" android:theme="@android:style/Theme.NoTitleBar" android:configChanges="orientation|keyboardHidden"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.SAMPLE_CODE"/> </intent-filter> </activity>
It seems redundant to repeat the package name in front of the class name
in the arguments of the
constructor
of
ComponentName.
But if we don’t,
startActivity
concatenates the two names with a slash and
throws the following exception.
Android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.android.apis/graphics.GLES20Activity}; have you declared this activity in yourAndroidManifest.xml?
MainActivity.javaactivity_main.xml.
The
TextView
and
RelativeLayout
have
id
numbers.
strings.xml.
The
textView
string
resource
contains a newline \n.AndroidManifest.xmlx.
Verify that the
ActivityNotFoundException
says
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.android.apis/com.example.android.apis.graphics.GLES20Activityx}; have you declared this activity in your AndroidManifest.xml?
Intent
that will call a phone number.
Genymotion said “Mobile network not available”
until I changed the 212 to 911.
final Uri uri = Uri.parse("tel:2125551212"); //Uniform Resource Identifier final Intent intent = new Intent(Intent.ACTION_CALL, uri); //vs. ACTION_DIAL.Add the following element immediately before the
application
element in
AndroidManifest.xml.CALL_PHONE
has an underscore.
See
Using
Permissions.
<uses-permission android:name="android.permission.CALL_PHONE"/>Find the TCP port number that the Android Emulator would use to talk to telnet. It’s displayed at the top of the Emulator and defaults to 5554. (5555 for Genymotion). But just to make sure,
netstat -a -f inet -p tcp (Macintosh Terminal) netstat -an -f inet -p tcp | awk 'NR <= 2 || /5554/' Active Internet connections (including servers) Proto Recv-Q Send-Q Local Address Foreign Address (state) tcp4 0 0 192.168.56.1.49448 192.168.56.101.5555 ESTABLISHED netstat -a -p TCP (Windows cmd.exe)To give an Emulator console command, we must telnet to the Android Emulator. See Telephony Emulation and Emulating Phone Operations in the Eclipse DDMS Perspective. On Macintosh,
telnet localhost 5554On Microsoft Windows, install PuTTY and launch
putty.exe.
Android Console: type 'help' for a list of commands
help
Android console command help:
help|h|? print a list of commands
event simulate hardware events
geo Geo-location commands
gsm GSM related commands (Global System for Mobile Communications)
cdma CDMA related commands (Code Division Multiple Access)
kill kill the emulator instance
network manage network settings
power power related commands
quit|exit quit control session
redir manage port redirections
sms SMS related commands (Short Mesage Service)
avd control virtual device execution
window manage emulator window
qemu QEMU-specific commands (Quick Emulator)
sensor manage emulator sensors
try 'help ' for command-specific help
OK
help gsm
allows you to change GSM-related settings, or to make a new inbound phone call
available sub-commands:
gsm list list current phone calls
gsm call create inbound phone call
gsm busy close waiting outbound call as busy
gsm hold change the state of an oubtound call to 'held'
gsm accept change the state of an outbound call to 'active'
gsm cancel disconnect an inbound or outbound phone call
gsm data modify data connection state
gsm voice modify voice connection state
gsm status display GSM status
gsm signal set sets the rssi and ber
OK
help gsm list
'gsm list' lists all inbound and outbound calls and their state
OK
Launch the app and let it call
gsm list outbound to 2125551212 : active OK gsm cancel 2125551212 (The emulator says CALL ENDED.) OK exit