Created
October 1, 2016 19:36
-
-
Save alvareztech/9542b89a8230d2a10e2c2b585f88b039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:id="@+id/activity_main" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:orientation="vertical" | |
| android:paddingBottom="@dimen/activity_vertical_margin" | |
| android:paddingLeft="@dimen/activity_horizontal_margin" | |
| android:paddingRight="@dimen/activity_horizontal_margin" | |
| android:paddingTop="@dimen/activity_vertical_margin" | |
| tools:context="tech.alvarez.intents.MainActivity"> | |
| <Button | |
| android:layout_width="match_parent" | |
| android:layout_height="48dp" | |
| android:onClick="abrirTelefono" | |
| android:text="@string/abrir_telefono" /> | |
| <Button | |
| android:layout_width="match_parent" | |
| android:layout_height="48dp" | |
| android:onClick="abrirWeb" | |
| android:text="@string/abrir_web" /> | |
| <Button | |
| android:layout_width="match_parent" | |
| android:layout_height="48dp" | |
| android:onClick="enviarCorreo" | |
| android:text="@string/enviar_correo" /> | |
| <Button | |
| android:layout_width="match_parent" | |
| android:layout_height="48dp" | |
| android:onClick="abrirMapa" | |
| android:text="@string/abrir_mapa" /> | |
| <Button | |
| android:layout_width="match_parent" | |
| android:layout_height="48dp" | |
| android:onClick="llamar" | |
| android:text="@string/llamar" /> | |
| </LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package tech.alvarez.intents; | |
| import android.content.Intent; | |
| import android.content.pm.PackageManager; | |
| import android.net.Uri; | |
| import android.os.Bundle; | |
| import android.support.annotation.NonNull; | |
| import android.support.v4.app.ActivityCompat; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.util.Log; | |
| import android.view.View; | |
| public class MainActivity extends AppCompatActivity { | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| } | |
| public void abrirTelefono(View view) { | |
| Uri numero = Uri.parse("tel:77242526"); | |
| Intent intent = new Intent(Intent.ACTION_DIAL); | |
| startActivity(intent); | |
| } | |
| public void abrirWeb(View view) { | |
| Uri web = Uri.parse("http://alvarez.tech/android-umsa"); | |
| Intent i = new Intent(Intent.ACTION_VIEW, web); | |
| startActivity(i); | |
| } | |
| public void enviarCorreo(View view) { | |
| Log.i("MIAPP", "Se presiono el boton de enviar correo"); | |
| Intent i = new Intent(Intent.ACTION_SEND); | |
| i.setType("text/plain"); | |
| i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]", "[email protected]"}); | |
| i.putExtra(Intent.EXTRA_SUBJECT, "Asunto"); | |
| i.putExtra(Intent.EXTRA_TEXT, "Este es el contenido del correo"); | |
| startActivity(i); | |
| } | |
| public void abrirMapa(View view) { | |
| // Uri lugar = Uri.parse("geo:-16.510947,-68.122074?z=8"); | |
| Uri lugar = Uri.parse("geo:0,0?q=Perez+Velasco,+La+Paz,+Bolivia"); | |
| Intent i = new Intent(Intent.ACTION_VIEW, lugar); | |
| startActivity(i); | |
| } | |
| public void llamar(View view) { | |
| if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) { | |
| Uri numero = Uri.parse("tel:74858056"); | |
| Intent intent = new Intent(Intent.ACTION_CALL, numero); | |
| startActivity(intent); | |
| } else { | |
| if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.CALL_PHONE)) { | |
| Log.i("MIAPP", "mostrar mensaje dar permiso manual"); | |
| } else { | |
| ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CALL_PHONE}, 777); | |
| } | |
| } | |
| } | |
| @Override | |
| public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | |
| super.onRequestPermissionsResult(requestCode, permissions, grantResults); | |
| if (requestCode == 777) { | |
| if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
| Log.i("MIAPP", "El usuario SI dio permiso"); | |
| } else { | |
| Log.i("MIAPP", "El usuario NO dio permiso"); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <resources> | |
| <string name="app_name">Intents</string> | |
| <string name="abrir_telefono">Abrir teléfono</string> | |
| <string name="abrir_web">Abrir web</string> | |
| <string name="enviar_correo">Enviar correo</string> | |
| <string name="abrir_mapa">Abrir mapa</string> | |
| <string name="llamar">Llamar</string> | |
| </resources> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment