Last active
June 10, 2016 03:02
-
-
Save alvareztech/0ff774d5024ec2e71fa76745afe3478a to your computer and use it in GitHub Desktop.
Parte del proyecto "Aplicacion 1" que se vio en la sesión 3 del curso de desarrollo de aplicaciones Android.
This file contains 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: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="com.danielalvarez.aplicacion1.MainActivity"> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="48dp" | |
android:onClick="abrir" | |
android:text="@string/nuevaActivity" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="48dp" | |
android:onClick="abrirWebsite" | |
android:text="@string/abrirWeb" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="48dp" | |
android:onClick="abrirEmail" | |
android:text="@string/abrirCorreo" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="48dp" | |
android:onClick="abrirMaps" | |
android:text="@string/abrirMapa" /> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="48dp" | |
android:onClick="llamarTelefono" | |
android:text="@string/llamar" /> | |
</LinearLayout> |
This file contains 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"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.danielalvarez.aplicacion1"> | |
<uses-permission android:name="android.permission.CALL_PHONE" /> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name=".MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity android:name=".SegundaActivity"></activity> | |
</application> | |
</manifest> |
This file contains 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 com.danielalvarez.aplicacion1; | |
import android.Manifest; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.net.Uri; | |
import android.os.Bundle; | |
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 abrir(View view) { | |
// esto se ejecuta cuando presiono el boton | |
Log.i("MIAPP", "Se presiono el boton abrir" + getString(R.string.hola)); | |
Intent intent = new Intent(this, SegundaActivity.class); | |
startActivity(intent); | |
getResources().getDimension(R.dimen.activity_horizontal_margin); | |
} | |
public void abrirWebsite(View view) { | |
Uri web = Uri.parse("http://alvarez.tech/cursos/android"); | |
Intent intent = new Intent(Intent.ACTION_VIEW, web); | |
startActivity(intent); | |
} | |
public void abrirEmail(View view) { | |
Intent i = new Intent(Intent.ACTION_SEND); | |
i.setType("text/plain"); | |
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"un@correo.com"}); | |
i.putExtra(Intent.EXTRA_SUBJECT, "Asunto del correo...."); | |
i.putExtra(Intent.EXTRA_TEXT, "Mensaje del correo..."); | |
startActivity(i); | |
} | |
public void abrirMaps(View view) { | |
Uri ubicacion = Uri.parse("geo:-16.504677,-68.129987?z=16"); | |
Intent i = new Intent(Intent.ACTION_VIEW, ubicacion); | |
startActivity(i); | |
// Uri ubicacion = Uri.parse("geo:0,0?q=Pérez+Velasco,+La+Paz,+Bolivia"); | |
// Intent i = new Intent(Intent.ACTION_VIEW, ubicacion); | |
// startActivity(i); | |
} | |
public void llamarTelefono(View view) { | |
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) { | |
// Podemos realizar la operación, tenemos permiso | |
Uri numero = Uri.parse("tel:72524595"); | |
Intent intent = new Intent(Intent.ACTION_CALL, numero); | |
startActivity(intent); | |
} else { | |
// No tenemos permiso | |
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) { | |
// Ya pedimos permiso anteriormente al usuario | |
Log.i("MIAPP", "vaya a confirguraciones para autorizar llamada"); | |
} else { | |
// No pedimos permiso antes, lo solicitamos | |
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, 7); | |
} | |
} | |
} | |
@Override | |
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { | |
switch (requestCode) { | |
case 7: | |
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
// El usuario permitió el uso | |
// Podemos continuar la acción | |
} else { | |
// El usuario denegó el permiso | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment