0% found this document useful (0 votes)
30 views

Recursos y Sensores: Lsub, Gysc, Urjc

The document discusses various Android intents that can be used to launch built-in activities and access system resources. It provides examples of intents for launching a web browser, conducting a web search, opening the camera, displaying location on a map, making phone calls, sending messages, and more. It also covers accessing sensors on Android devices and registering listeners to receive sensor events.

Uploaded by

vasco04
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Recursos y Sensores: Lsub, Gysc, Urjc

The document discusses various Android intents that can be used to launch built-in activities and access system resources. It provides examples of intents for launching a web browser, conducting a web search, opening the camera, displaying location on a map, making phone calls, sending messages, and more. It also covers accessing sensors on Android devices and registering listeners to receive sensor events.

Uploaded by

vasco04
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Recursos y sensores

LSUB, GYSC, URJC

Thursday, April 18, 13

Intro
En este tema veremos: Algunos recursos del sistema que se
dispositivo.

acceden simplemente lanzando un Intent.

El uso de los sensores disponibles en el

Thursday, April 18, 13

Navegador

URI:

http://web_address https://web_address

Intent Action: Intent.ACTION_VIEW

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://lsub.org/")); startActivity(intent);

Thursday, April 18, 13

Bsqueda Web

Hay que especicar la consulta en un extra. Intent Action: Intent.ACTION_WEB_SEARCH

Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, "lsub"); startActivity(intent);

Thursday, April 18, 13

Cmara

IntentAction:

android.media.action.IMAGE_CAPTURE

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivity(intent);

Thursday, April 18, 13

Localizacin Geogrca

URI:

geo:latitude,longitude

Intent Action: Intent.ACTION_VIEW

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:40.282100,-3.819761")); startActivity(intent);

Thursday, April 18, 13

Google Street View



URI:

google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapZoom

Intent Action: Intent.ACTION_ VIEW

Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("google.streetview:cbll=40.420280,"+ "-3.705660&cbp=1,0,,0,1.0&mz=mapZoom")); startActivity(intent);

Thursday, April 18, 13

Llamadas

URI:

tel:phone_number

Intent Action: Intent.ACTION_CALL

Intent intent = new Intent(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + phone)); startActivity(intent);

Thursday, April 18, 13

Mensaje de texto
Sirve para enviar correos, tweets, etc. Intent Action: Intent.ACTION_SEND
Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, "Speak patterns"); intent.putExtra(Intent.EXTRA_TEXT, "Please, do not speak backwards in the next meeting."); intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"[email protected]"}); startActivity(intent);

Thursday, April 18, 13

Recibir mensajes

El maniesto tiene que especicar que una Activity acepta dichos mensajes:
<activity android:name="com.example.androidservicios.TextReceiverActivity" android:label="@string/recv_activity_name" > <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </intent-filter> </activity>

Thursday, April 18, 13

Recibir mensajes

La Activity receptora puede extraer los parmetros del Intent en el mtodo onCreate:
Bundle extras = getIntent().getExtras(); String[] extra_email = (String[]) extras.get(Intent.EXTRA_EMAIL); String msg = extras.getString(Intent.EXTRA_TEXT); String subject = extras.getString(Intent.EXTRA_SUBJECT); // text is a TextView object in this example text.setText("Message to: " ); for(String s: extra_email){ text.append(s + " "); } text.append("\nSubject: " + subject); text.append("\nMessage: " + msg);

Thursday, April 18, 13

Mensaje binario
Tambin podemos enviar datos binarios. Intent Action: Intent.ACTION_SEND
Resources resources = getResources(); String uritext = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(R.raw.yoda) + '/' + resources.getResourceTypeName(R.raw.yoda) + '/' + resources.getResourceEntryName(R.raw.yoda) + ".jpg"; Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(uritext)); intent.setType("image/jpeg"); startActivity(intent);

Thursday, April 18, 13

Otras
En la documentacin de la clase Intent se
describen otras Intents interesantes, como activar los comandos de voz, etc.

http://developer.android.com/reference/android/content/Intent.html

Thursday, April 18, 13

Sensores
Hay varios tipos de sensores: Movimiento: aceleracin, rotacin, etc. Entorno: luz, temperatura, etc. Posicin: magnetmetro, etc. Podemos determinar cules tiene nuestro
dispositivo Android.
Thursday, April 18, 13

Sensores
smanager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); List<Sensor> devices = smanager.getSensorList(Sensor.TYPE_ALL); // show the sensors info in a text view for(Sensor s: devices){ text.append(s.toString() + "\n"); }

Thursday, April 18, 13

Sensores

Podemos preguntar al sistema si hay disponible un sensor de un tipo dado (TYPE_GYROSCOPE, TYPE_LINEAR_ACCELERATION, TYPE_GRAVITY, etc.)
lightsensor = smanager.getDefaultSensor(Sensor.TYPE_LIGHT); if(lightsensor != null){ llistener = new LightListener(); text.append("Listening events from the light sensor.\n"); }else{ text.append("No light sensor.\n"); }

Thursday, April 18, 13

Sensores

Para usar un sensor hay que registrar un objeto que implemente la interfaz SensorEventListener. Hay que elegir la frecuencia de recepcin de los eventos. Implementar los callbacks:

onAccuracyChanged(): se invoca cuando cambia la precisin del objeto sensor (low, medium, high, unreliable). onSensorChanged(): se invoca cuando el sensor tiene un nuevo valor.

Thursday, April 18, 13

Sensores
@Override protected void onResume() { super.onResume(); level.setProgress(0); smanager.registerListener(llistener, lightsensor, SensorManager.SENSOR_DELAY_NORMAL); } @Override protected void onPause() { super.onPause(); smanager.unregisterListener(llistener); }

Thursday, April 18, 13

Sensores
private class LightListener implements SensorEventListener{ // lightsensor.getMaximumRange() is too high (72945) for // the environment. private final double MAX = 500.0; } @Override public void onAccuracyChanged(Sensor sensor, int accuracy) { return; } @Override public void onSensorChanged(SensorEvent event) { Double d = event.values[0] / MAX * 100.0; if(d > 100.0) d = 100.0; // level is a ProgressBar widget level.setProgress(d.intValue()); }

Thursday, April 18, 13

Sensores

Thursday, April 18, 13

El emulador no soporta sensores. Hay que desregistrar los listeners cuando no nos interesan los datos del sensor o cuando la Activity no est activa. El callback debe ser pequeo. Antes de usar un sensor hay que comprobar que est disponible en el sistema. Hay que elegir con cuidado la frecuencia de recepcin de eventos para nuestra aplicacin.

You might also like