miércoles, 18 de septiembre de 2013

Android: Generar R.java manualmente

Me encontré recientemente con el error de  que no se genera el archivo R.java. Revisando algunos portales logre llegar a la solución con este pequeño script.

PATH_ANDROID=programs/android-studio/sdk/build-tools/android-4.2.2
PATH_MANIFEST=workspaces/DefaultWorkspace/MyApp/AndroidManifest.xml
PATH_RESOURCE=workspaces/DefaultWorkspace/MyApp/res
PATH_LIBS=workspaces/DefaultWorkspace/MyApp/libs
PATH_GENERATE=workspaces/DefaultWorkspace/MyApp/gen

$PATH_ANDROID/aapt package --non-constant-id -f -m \
-M $PATH_MANIFEST \
-S $PATH_RESOURCE \
-I $PATH_LIBS \
-J $PATH_GENERATE --generate-dependencies


El script esta basado en rutas que crea Eclipse, si usas otro IDE puedes cambiar las rutas a las que se ajusten a tu IDE.

Suerte.

(Para hacerlo en Eclipse de forma visual, botón derecho sobre el proyecto -> Android Tools -> Fix project properties)

miércoles, 4 de septiembre de 2013

Android: Compartir en redes sociales especificas

En el post anterior pudimos compartir en redes sociales, en esta ocación vamos a compartir en redes especificas, como "sólo en facebook" o "sólo por correo", para esto creamos en nuestro Activity el siguiente método:

void shareSpecificSocialNetwork(String nameApp, String title,
            String extraTitle, String filename) {
        try {
            List targetedShareIntents = new ArrayList();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/jpeg");
            List resInfo = getPackageManager()
                    .queryIntentActivities(share, 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    Intent targetedShare = new Intent(
                            android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/jpeg");
                    if (info.activityInfo.packageName.toLowerCase().contains(
                            nameApp)
                            || info.activityInfo.name.toLowerCase().contains(
                                    nameApp)) {
                        targetedShare.putExtra(Intent.EXTRA_SUBJECT,
                                "Sample Photo");
                        targetedShare.putExtra(Intent.EXTRA_TEXT, extraTitle);
                        targetedShare.putExtra(Intent.EXTRA_STREAM,
                                Uri.fromFile(new File(filename)));
                        targetedShare.setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }
                Intent chooserIntent = Intent.createChooser(
                        targetedShareIntents.remove(0), title);
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetedShareIntents.toArray(new Parcelable[] {}));
                startActivity(chooserIntent);
            }
        } catch (Exception e) {
            Log.v("PensandoEnBinario", e.getMessage());
        }
    }


Igual que el anterior blog deberíamos crear un botón que ejecute el evento de compartir en facebook:

Button btnFacebook = (Button) dialog
                        .findViewById(R.id.dialogButtonFacebook);
                btnFacebook.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        shareSpecificSocialNetwork("facebook","PensandoEnBinario",
                                 "Powered by PensandoEnBinario",inputFilename);
                    }
                });


Listo podemos probar con: facebook, twitter, mail, instagram, etc.


Android: Compartir en redes sociales

En esta ocasión vamos a compartir texto e imágenes en las distintas redes sociales, para esto vamos a añadir a nuestro Activity el siguiente método

public void shareSocialNetwork(String title, String extraTitle,
            String filename) {
        Intent share = new Intent(Intent.ACTION_SEND);
        share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filename)));
        share.putExtra(Intent.EXTRA_TITLE, extraTitle);
        share.putExtra(Intent.EXTRA_SUBJECT, extraTitle);
        share.setType("image/png");
        startActivity(Intent.createChooser(share, title));
    }


Este método es el encargado de mostrar el dialogo para la selección de redes sociales y los valores por defecto a compartir.

Para ejecutarlo creamos un botón con id btnShare al cual le asignaremos el evento:

ImageButton btnShare = (ImageButton) findViewById(R.id.btnShare);
        btnShare.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

               shareSocialNetwork("
PensandoEnBinario",
             "Powered by PensandoEnBinario",inputFilename); //inputFilename es una imagen (uri) para compartir
}
});


Listo, ya tenemos un botón que permite compartir en las redes sociales.

Android FullScreen Activity

Muchas aplicaciones móviles requieren mostrarse en FullScreen, para esto tenemos dos posibilidades

Fullscreen en toda la aplicación:

Es necesario editar el archivo :
AndroidManifest.xml
Y en la sección application se añade el parametro:
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

Fullscreen en pantallas especificas:

Es necesario en el método: onCreate
añadir las siguientes líneas (después de super.onCreate(savedInstanceState)):

 requestWindowFeature(Window.FEATURE_NO_TITLE);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
 WindowManager.LayoutParams.FLAG_FULLSCREEN);


Listo!!

Configure Grafana and Slack

To configure Grafana to send alerts to Slack, you need to set up a notification channel in Grafana and configure it to use the Slack integra...