Coder Social home page Coder Social logo

snippets-android's Introduction

Firebase Android Snippets

This repository holds code snippets used in Android documentation on firebase.google.com.

Contributing

We love contributions! See CONTRIBUTING.md for guidelines.

Actions Status

snippets-android's People

Contributors

albertoazinar avatar betrisey avatar bhparijat avatar bojeil-google avatar chibatching avatar dpebot avatar ersin-ertan avatar gkaldev avatar harshithdwivedi avatar hborderstwitch avatar jlara310 avatar jvanderwee avatar kevinthecheung avatar kroikie avatar lukedaniel16 avatar marinacoelho avatar markarndt avatar markduckworth avatar mikelehen avatar morganchen12 avatar peterfriese avatar puf avatar samtstern avatar someshbhalsing avatar thatfiredev avatar ulukaya avatar vkryachko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

snippets-android's Issues

ะ’

private void onInviteClicked() {
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
.setCallToActionText(getString(R.string.invitation_cta))
.build();
startActivityForResult(intent, REQUEST_INVITE);
}

Build error

Hi @samtstern I was trying to build the project so that I could convert the newly added snippets to Kotlin but the project build fails with the following message :

The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.2,15.0.2], [16.0.0,16.0.0]], but resolves to 15.0.2. 

Any ideas as to what might be causing the trouble here?
Looked up on stackoverflow and the answers suggested updating google-services and dependencies to the latest version (which is already done).

Other Details

google-services version : 4.0.1
gradle plugin : 3.1.3

StartActivityForResult is an outdated method for doing this

It was misleading to some of my developers when they went from firebase docs to here and ended up using this for grabbing a result. It shows up as a deprecated library in android studio, and is considered the outdated way to do this. This likely needs to be updated.

Links for new way:
https://developer.android.com/training/basics/intents/result
https://stackoverflow.com/questions/62671106/onactivityresult-method-is-deprecated-what-is-the-alternative

viewBinding Update Code

We can use viewBinding in the code which is updated version and also recommended by the Google.
So please update the code

I am getting com.google.android.gms.common.api.ApiException: 4: 4:

I am using Firebase auth to signin user with Google, and I have setup the Firebase project with proper configuration and google-services.json and add that to my android project. I have added below dependencies in my
build-gradle.kts(project) id("com.google.gms.google-services") version "4.4.1" apply false
build.gradle.kts(app)
implementation("com.google.firebase:firebase-auth:22.3.1") implementation(platform("com.google.firebase:firebase-bom:32.8.0")) implementation("com.google.android.gms:play-services-auth:21.0.0")

This is my mainactivity.ky

`
private fun signIn(){
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build()
googleSignInClient = GoogleSignIn.getClient(this, gso)
val signInIntent = googleSignInClient.signInIntent
startActivityForResult(signInIntent, SIGNIN_CODE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == SIGNIN_CODE) {
        val task = GoogleSignIn.getSignedInAccountFromIntent(data)
        try {
            // Google Sign In was successful, authenticate with Firebase
            val account = task.getResult(ApiException::class.java)!!
            Log.d(TAG, "firebaseAuthWithGoogle:" + account.id)
            firebaseAuthWithGoogle(account.idToken!!)
        } catch (e: ApiException) {
            // Google Sign In failed, update UI appropriately
            Log.w(TAG, "Google sign in failed", e)
        }
    }
}

private fun firebaseAuthWithGoogle(idToken: String) {
    val credential = GoogleAuthProvider.getCredential(idToken, null)
    auth.signInWithCredential(credential)
        .addOnCompleteListener(this) { task ->
            if (task.isSuccessful) {
                // Sign in success, update UI with the signed-in user's information
                Log.d(TAG, "signInWithCredential:success")
                val user = auth.currentUser
                Toast.makeText(this, "Login Successfull", Toast.LENGTH_SHORT).show()
            } else {
                // If sign in fails, display a message to the user.
                Log.w(TAG, "signInWithCredential:failure", task.exception)
                Toast.makeText(this, "Login Failed", Toast.LENGTH_SHORT).show()
            }
        }
}

This is giving me random results, I am able to log in successfully sometimes, and sometimes I am gettingcom.google.android.gms.common.api.ApiException: 4: 4: ` exception, I am not sure what is wrong, I tried everything, to add value ofdefault_web_client_id to string.xml to remove that, and invalidate and restart my projects too.

An internal error has occurred

Requests to this API identitytoolkit method google.cloud.identitytoolkit.v1.AuthenticationService.SignUp are blocked.

Align documentation and code sample on how to manually track screens

The Google Analytics documentation, under Manually track screens, says:

You can manually log screen_view events whether or not automatic tracking is enabled. You can log these events in the onAppear or viewDidAppear methods for Apple platforms and onResume for Android. When screen_class is not set, Analytics sets a default value based on the UIViewController or Activity that is in focus when the call is made.

The code sample, however, does it inside onCreate.

Looking at the lifecycle, having it in onResume would mean that after the device wakes from sleep, another event would be sent.

Sebas

https://github.com/firebase/snippets-android/blob/b8f65e9150fe927a5f0473e15e16fa5803189b60/analytics/app/src/main/java/com/google/firebase/example/analytics/kotlin/MainActivity.kt#L237-L241

Region Tag: run_task_executor

Hi folks,
A few region tags prefixed with run_ should be changed to something like firebase_run_task_executor.

This is messing up the snippet tracker, as it assumes run_ samples associate with Cloud Run.

Can we just change the region tag or do we need to do some internal config changes too?

Convert database snippet to kotlin

Hi @samtstern
As discussed here, I would like to convert the database code to Kotlin.
Could you tell me the structure I should follow?
Should i create a new project for database in Kotlin or create a kotlin file for each java file in the current project?

Docs: Code snippet for City class does not match Java version

Environment details

Documentation on https://firebase.google.com/

Steps to reproduce

  1. Open the Add data to Cloud Firestore page in the docs.
  2. Compare the "Java" and "Java Android" code snippets under Custom objects
  3. Notice that there a significant inconsistencies, and that both versions only show part of the class.

External references such as API reference guides

Any additional information below

Related issue on Java snippet googleapis/java-firestore#876

See pull request #323

https://github.com/firebase/snippets-android/blob/b8f65e9150fe927a5f0473e15e16fa5803189b60/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/FirebaseUIActivity.kt#L19

// Create a storage reference from our app val storageRef = storage.reference // Create a reference with an initial file path and name val pathReference = storageRef.child("images/stars.jpg") // Create a reference to a file from a Google Cloud Storage URI val gsReference = storage.getReferenceFromUrl("gs://bucket/images/stars.jpg") // Create a reference from an HTTPS URL // Note that in the URL, characters are URL escaped! val httpsReference = storage.getReferenceFromUrl( "https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg")StorageActivity.kt

// Create a storage reference from our app
val storageRef = storage.reference
// Create a reference with an initial file path and name
val pathReference = storageRef.child("images/stars.jpg")
// Create a reference to a file from a Google Cloud Storage URI
val gsReference = storage.getReferenceFromUrl("gs://bucket/images/stars.jpg")
// Create a reference from an HTTPS URL
// Note that in the URL, characters are URL escaped!
val httpsReference = storage.getReferenceFromUrl(
"https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg")

new AUTHUI reeor

// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build(),
new AuthUI.IdpConfig.TwitterBuilder().build());
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);

onActivityResult is deprecated in FirebaseUI AuthUI snippet

It's recommended instead that you use registerForActivityResult() instead to launch an activity. Developer reference: https://developer.android.com/training/basics/intents/result

Affected snippet:

private fun createSignInIntent() {
// [START auth_fui_create_intent]
// Choose authentication providers
val providers = arrayListOf(
AuthUI.IdpConfig.EmailBuilder().build(),
AuthUI.IdpConfig.PhoneBuilder().build(),
AuthUI.IdpConfig.GoogleBuilder().build(),
AuthUI.IdpConfig.FacebookBuilder().build(),
AuthUI.IdpConfig.TwitterBuilder().build())
// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN)
// [END auth_fui_create_intent]
}
// [START auth_fui_result]
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == RC_SIGN_IN) {
val response = IdpResponse.fromResultIntent(data)
if (resultCode == Activity.RESULT_OK) {
// Successfully signed in
val user = FirebaseAuth.getInstance().currentUser
// ...
} else {
// Sign in failed. If response is null the user canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
// ...
}
}
}
// [END auth_fui_result]

Devlopment

Growth ๐Ÿ’น๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ“ˆ๐Ÿ’น๐Ÿ’น๐Ÿ’น๐Ÿ’น

Get prediction values from tensorflow lite android

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow):No
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows 10 x64
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on a mobile device: Samsung A3 2016
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below):1.13.1
  • Python version:3.6.8
  • Bazel version (if compiling from source):
  • GCC/Compiler version (if compiling from source):
  • CUDA/cuDNN version:9.0/7.4
  • GPU model and memory: Nvidia Geforce 840m 3 Go

Describe the current behavior
I want to get values from output tensor with input an image to predict the eye region landmarks.
I have predicted image from frozen graph model and Tensorflow lite using python script and it works fine.
The problem is with the Android platform, I got false and different values compared to values from python script

Describe the expected behavior

Code to reproduce the issue
Python script

data = np.asarray( img, dtype="float32" ) 

# Inference on input data normalized to [0, 1]
inputImg = np.expand_dims(data,0).astype(np.float32)
input_details = interpreter.get_input_details()
interpreter.set_tensor(input_details[0]['index'], inputImg)

interpreter.invoke()

output_details = interpreter.get_output_details()
output_data = interpreter.get_tensor(output_details[0]['index'])
print(output_data)

Java code ( Android Environment )

private float[][][][] bitmapToInputArray() {
        // [START mlkit_bitmap_input]
        Bitmap bitmap= getYourInputImage();
        bitmap = Bitmap.createScaledBitmap(bitmap, 112, 112, true);

        int batchNum = 0;
        float[][][][] input = new float[1][112][112][3];
        for (int x = 0; x < 112; x++) {
            for (int y = 0; y < 112; y++) {
                int pixel = bitmap.getPixel(x, y);
                // Normalize channel values to [-1.0, 1.0]. This requirement varies by
                // model. For example, some models might require values to be normalized
                // to the range [0.0, 1.0] instead.
                input[batchNum][x][y][0] = (Color.red(pixel) - 127) / 128.0f;
                input[batchNum][x][y][1] = (Color.green(pixel) - 127) / 128.0f;
                input[batchNum][x][y][2] = (Color.blue(pixel) - 127) / 128.0f;
                Log.i("Input","input"+input[batchNum][x][y]);

            }
        }
        // [END mlkit_bitmap_input]

      return input;
    }

 private void useInferenceResult(float[] probabilities) throws IOException {
        String[] result=new String[80];
        String x="";
        String y="";
        ArrayList<Point> listpoint= new ArrayList<Point>();

        double viewWidth = canvas.getWidth();
        double viewHeight = canvas.getHeight();
        double imageWidth = mutableBitmap.getWidth();
        double imageHeight = mutableBitmap.getHeight();
        Log.i("viewWidth","viewwidth "+viewWidth);
        Log.i("viewHeight","viewheight "+viewHeight);
        Log.i("imagewidth","imagewidth "+imageWidth);
        Log.i("imaageHeigh","imageheigh "+imageHeight);
        double scale = Math.min(viewWidth / imageWidth, viewHeight / imageHeight);
        Log.i("Scale","Scale"+scale);
        try {
            for (int i = 0; i < probabilities.length; i++) {

                Log.i("MLKit", String.format("%1.8f", probabilities[i]));
                float i1 = probabilities[i];
                Log.i("floaaat", "" + i1);
            }
        }

Other info / logs

  • That what I should get : ( this is from python script using Tensorflow lite model ):

[[0.3323875 0.19654518 0.3430611 0.17367488 0.3671013 0.16478491
0.39022946 0.17491257 0.399131 0.19814822 0.3900888 0.22294888
0.36448467 0.23006389 0.34123936 0.21979642 0.30286688 0.20466375
0.31792122 0.19202346 0.33909258 0.18460245 0.3652809 0.18118384
0.39127237 0.18584773 0.40995973 0.19605562 0.42233318 0.21089557
0.40651116 0.2182863 0.38454503 0.22073016 0.3601514 0.22152397
0.3375371 0.21898884 0.31742495 0.2137229 0.628366 0.21445222
0.63888156 0.19114998 0.6626687 0.18333182 0.6856534 0.1955274
0.69444335 0.22068903 0.6838143 0.2438955 0.66011566 0.2518409
0.63507193 0.2414121 0.60496974 0.22573914 0.6209617 0.21241865
0.6422507 0.20397455 0.6683734 0.20254172 0.6917013 0.2092008
0.7084733 0.21974358 0.7189961 0.23459744 0.70730895 0.24100597
0.69019526 0.24282111 0.6691431 0.24188581 0.6451422 0.23857626
0.6218671 0.2344214 ]]

  • Those values are from Android Studio ( java using Log.i) :

2019-08-17 14:47:50.617 21349-21349/com.example.irisdetection I/MLKit: 0,23961355
2019-08-17 14:47:50.620 21349-21349/com.example.irisdetection I/MLKit: 0,25104424
2019-08-17 14:47:50.621 21349-21349/com.example.irisdetection I/MLKit: 0,28179651
2019-08-17 14:47:50.622 21349-21349/com.example.irisdetection I/MLKit: 0,31467810
2019-08-17 14:47:50.623 21349-21349/com.example.irisdetection I/MLKit: 0,33257431
2019-08-17 14:47:50.624 21349-21349/com.example.irisdetection I/MLKit: 0,32645294
2019-08-17 14:47:50.625 21349-21349/com.example.irisdetection I/MLKit: 0,29138848
2019-08-17 14:47:50.626 21349-21349/com.example.irisdetection I/MLKit: 0,25581932
2019-08-17 14:47:50.627 21349-21349/com.example.irisdetection I/MLKit: 0,19593856
2019-08-17 14:47:50.628 21349-21349/com.example.irisdetection I/MLKit: 0,21698779
2019-08-17 14:47:50.631 21349-21349/com.example.irisdetection I/MLKit: 0,24266151
2019-08-17 14:47:50.632 21349-21349/com.example.irisdetection I/MLKit: 0,27562365
2019-08-17 14:47:50.633 21349-21349/com.example.irisdetection I/MLKit: 0,30823168
2019-08-17 14:47:50.635 21349-21349/com.example.irisdetection I/MLKit: 0,33465266
2019-08-17 14:47:50.636 21349-21349/com.example.irisdetection I/MLKit: 0,35355449
2019-08-17 14:47:50.637 21349-21349/com.example.irisdetection I/MLKit: 0,34009647
2019-08-17 14:47:50.638 21349-21349/com.example.irisdetection I/MLKit: 0,31358159
2019-08-17 14:47:50.640 21349-21349/com.example.irisdetection I/MLKit: 0,28156102
2019-08-17 14:47:50.642 21349-21349/com.example.irisdetection I/MLKit: 0,25063315
2019-08-17 14:47:50.643 21349-21349/com.example.irisdetection I/MLKit: 0,21878451
2019-08-17 14:47:50.644 21349-21349/com.example.irisdetection I/MLKit: 0,69623101
2019-08-17 14:47:50.646 21349-21349/com.example.irisdetection I/MLKit: 0,70167470
2019-08-17 14:47:50.646 21349-21349/com.example.irisdetection I/MLKit: 0,73317540
2019-08-17 14:47:50.648 21349-21349/com.example.irisdetection I/MLKit: 0,76974392
2019-08-17 14:47:50.649 21349-21349/com.example.irisdetection I/MLKit: 0,79195201
2019-08-17 14:47:50.651 21349-21349/com.example.irisdetection I/MLKit: 0,78359401
2019-08-17 14:47:50.652 21349-21349/com.example.irisdetection I/MLKit: 0,75674009
2019-08-17 14:47:50.653 21349-21349/com.example.irisdetection I/MLKit: 0,71786618
2019-08-17 14:47:50.654 21349-21349/com.example.irisdetection I/MLKit: 0,66782737
2019-08-17 14:47:50.655 21349-21349/com.example.irisdetection I/MLKit: 0,68930006
2019-08-17 14:47:50.656 21349-21349/com.example.irisdetection I/MLKit: 0,71668541
2019-08-17 14:47:50.657 21349-21349/com.example.irisdetection I/MLKit: 0,75279719
2019-08-17 14:47:50.658 21349-21349/com.example.irisdetection I/MLKit: 0,78872705
2019-08-17 14:47:50.659 21349-21349/com.example.irisdetection I/MLKit: 0,81867975
2019-08-17 14:47:50.661 21349-21349/com.example.irisdetection I/MLKit: 0,83806717
2019-08-17 14:47:50.662 21349-21349/com.example.irisdetection I/MLKit: 0,82371044
2019-08-17 14:47:50.664 21349-21349/com.example.irisdetection I/MLKit: 0,79749656
2019-08-17 14:47:50.665 21349-21349/com.example.irisdetection I/MLKit: 0,76317006
2019-08-17 14:47:50.666 21349-21349/com.example.irisdetection I/MLKit: 0,72700304
2019-08-17 14:47:50.667 21349-21349/com.example.irisdetection I/MLKit: 0,69159627

How can I solve this problem??

Phone Authentication Firebase

From 22nd January Android Play Services is unable to detect the Auto-Complete for the OTP.
Is there any guide which needs to be followed like SMS API in case of Firebase Phone Auth?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.