viernes, 5 de junio de 2020

Audio android java

A continuación, se muestra un ejemplo de cómo reproducir un archivo de audio que está disponible como recurso local sin procesar (guardado en el directorio res/raw/ de tu app):
    MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
    mediaPlayer.start(); // no need to call prepare(); create() does that for you

martes, 7 de enero de 2020

Error 12501 authenticating with google sign-in


<manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.demilion.dontpoopyourpants">


    <application        android:supportsRtl="true"        android:allowBackup="true"        android:fullBackupContent="false"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >

        <meta-data android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />
        <meta-data android:name="com.google.android.gms.version"                   android:value="@integer/google_play_services_version"/>

        <activity            android:name="com.google.example.games.tanc.MainActivity"            android:label="@string/title_activity_main"            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Keystore file does not exist

The debug keystore file isn't in your application's directory, it's in your .android directory. If you're using Windows, it's probably in C:\Users\yourname\.android (where instead of "yourname" use your own User directory).
Once you know where it is, you can run the keytool like this:
    keytool -list -v -keystore "C:\Users\yourname\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

Specify client ID settings

Next, specify your client ID settings by following the instructions specific to your platform.

Android


  1. Choose Installed application as your Application type and select Android as the installed application type (these should be your only options).
  2. In the Package name field, enter your Android application's package name.
  3. Open a terminal and run the Keytool utility to get the SHA1 fingerprint of the certificate. You should get both the release and debug certificate fingerprints.
    To get the release certificate fingerprint:
    keytool -list -keystore <path-to-production-keystore>
    
    To get the debug certificate fingerprint:
    keytool -list -keystore <path-to-debug-keystore>
    



--androiddebugkey

4. The keytool prompts you to enter a password for the keystore. The default password for the debug keystore is android. The keytool then prints the fingerprint to the terminal.

5. Paste the SHA1 fingerprint into the Signing certificate fingerprint (SHA1) field.



6. Click the Create client button, then follow the steps in the Gather credentials for authentication and authorization section below.

see on:

lunes, 6 de enero de 2020

Do Something on First App Start Only - Android Studio Tutorial

Do Something on First App Start Only


public class MainMenu extends Activity {
  


    @Override    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_basic_views);

        SharedPreferences prefs  = getSharedPreferences("prefs", MODE_PRIVATE);
        boolean firstStart = prefs.getBoolean("firstStart", true);

        if(firstStart)
        { showStartDialog();}

    }

    public void showStartDialog()
    {
        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(v.getContext());
        builder.setMessage("Check more apps!!!")
                .setCancelable(false)
                .setPositiveButton("OK GO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=Demilion") ) );
                    }
                })
                .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        builder.create()
                .show();

        SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean("fistStart", false);
        editor.apply();
    }





https://www.youtube.com/watch?v=2I1n6A6JJzw

miércoles, 1 de enero de 2020

Passing Data To Other Activity Using Intent.

  1. Create a New Explicit or Implicit Intent object in source activity.
  2. Call intent.putExtra(String key, Object data) method to save data in it.
  3. Call startActivity(intent) method in source activity to pass the intent to android os.
  4. Call getIntent() method in target activity.
  5. Use intent.getStringExtra(String key) to get the transferred data.
This-

Intent intent = new Intent(this, BasicViewsActivity.class);
intent.putExtra("amountTime", String.valueOf(amountTime));
startActivity(intent);

BasicViewActivity-

Intent intent = getIntent();
String amountTime =   intent.getStringExtra("amountTime");


https://www.dev2qa.com/passing-data-between-activities-android-tutorial/

jueves, 26 de diciembre de 2019

Send data from javascript to Native Android app.

Hello, here is sample code about how to send data from HTML/Javascript to native Android app using webview.
webview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

mypage.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta
        name="viewport"
        content="width=device-width; user-scalable=0;" />
    <title>HTML Android</title>
</head>
<body>
    <h1>HTML Android</h1>
    <input
        type="button"
        value="Button 1"
        onClick="sendDataToAndroid('Button 1 is click')" />

    <input
        type="button"
        value="Button 2"
        onClick="sendDataToAndroid('Button 2 is click')" />

    function sendDataToAndroid(toast) {
        MyFunction.onButtonClick(toast);
    }
</body>
</html>
WebViewActivity.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;

@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
public class WebViewActivity extends Activity {

    WebView mWebViewDemo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);
        mWebViewDemo = (WebView) findViewById(R.id.webview);
        ButtonClickJavascriptInterface myJavaScriptInterface = new ButtonClickJavascriptInterface(WebViewActivity.this);
        mWebViewDemo.addJavascriptInterface(myJavaScriptInterface, "MyFunction");
        mWebViewDemo.getSettings().setJavaScriptEnabled(true);
        mWebViewDemo.loadUrl("file:///android_asset/mypage.html");

    }

    public class ButtonClickJavascriptInterface {
        Context mContext;
        ButtonClickJavascriptInterface(Context c) {
            mContext = c;
        }

        @JavascriptInterface
        public void onButtonClick(String toast) {
            Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
        }
    }

}