This repository holds code snippets used in Android documentation on firebase.google.com.
We love contributions! See CONTRIBUTING.md for guidelines.
Android snippets for firebase.google.com
License: Apache License 2.0
This repository holds code snippets used in Android documentation on firebase.google.com.
We love contributions! See CONTRIBUTING.md for guidelines.
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).
google-services version : 4.0.1
gradle plugin : 3.1.3
Hi @samtstern
Would love to convert the snippets of Auth module to Kotlin, lmk if I can go ahead.
// TODO: Add SDKs for Firebase products that you want to use
@OverRide
public void sendInvite(Context context) {
super.sendInvite(context);
Toast.makeText(context, "TODO: TODO: Implement social sending", Toast.LENGTH_SHORT).show();
}
In the function, how to share the data to a specific application on the device? like facebook.
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
The documentation recommends logging SCREEN_VIEW
in the onResume
method. Which one is more appropriate?
Originally posted by @AVI5HEK in #347 (comment)
I'll try to use the Firebase auth reference on my project, but it won't works.
Our public style guide forbids use of the term "whitelist" in favor of more neutral terms like "access control list", "access list", or "allow list". Samples from this repo containing those terms are included in pages on firebase.google.com and need to be updated to comply with our updated style guide.
We can use viewBinding in the code which is updated version and also recommended by the Google.
So please update the code
What do you want ?
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 getting
com.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.
startActivityForResult(Intent,int)
is deprecated, please update your snippet and documentation
Requests to this API identitytoolkit method google.cloud.identitytoolkit.v1.AuthenticationService.SignUp are blocked.
Add in snippets for measure ad revenue for various mediation networks.
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.
In reference to what @SUPERCILEX mentioned here, we should avoid hungarian notation in our Kotlin snippets.
https://twitter.com/SUPERCILEX/status/1050544888733818880?s=19
I saw #5 and #12 and the resulting Kotlin Activities (looks great btw). So I was wondering if I could do the same for the dynamic-links, firebaseoptions, storage and tasks code snippets.
Just let me know and I'll start working on a PR
Adding code snippet for ChildEventListener in Java and Kotlin.
@samtstern working on this, will send a PR :)
This reference tends to change value after a minute to false, so it blocks my access to Firebase, please tell me any solution or alternative, I just want to detect if the device has a connection to the database to make changes with the internet or just local
As the title says, the MyFirebaseMessagingService.java file is missing the sendNotification() example method which I should add to my main java Please inform me about this. Thank you
https://github.com/firebase/snippets-android/blob/b8f65e9150fe927a5f0473e15e16fa5803189b60/analytics/app/src/main/java/com/google/firebase/example/analytics/kotlin/MainActivity.kt#L237-L241
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?
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?
Documentation on https://firebase.google.com/
Related issue on Java snippet googleapis/java-firestore#876
See pull request #323
#[[email protected]](
https://github.com/firebase/snippets-https://github.com/firebase/snippets-android/blob/b8f65e9150fe927a5f0473e15e16fa5803189b60/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/FirebaseUIActivity.kt#L19android/blob/b8f65e9150fe927a5f0473e15e16fa5803189b60/auth/app/src/main/java/com/google/firebase/quickstart/auth/kotlin/FirebaseUIActivity.kt#L18https://github.com/firebase/snippets-android/tree/bc2ea696c793c29f3bbcebfe31a9877e6eef20ab/admob/app[](url)`)`
Since startActivityForResult depricated how to target GoogleSignIn for new android versions
in the CONTRIBUTING.md the Feature Requests sub-cat (that should be at: https://github.com/firebase/snippets-android/blob/master/CONTRIBUTING.md#feature) leads to nothing. Should it be added/removed?
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:
Growth ๐น๐๐๐น๐น๐น๐น๐๐๐๐๐น๐น๐น๐น๐น๐น๐น๐น๐๐๐๐๐๐๐๐น๐น๐น๐๐๐๐๐๐น๐น๐น๐น
System information
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
[[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 ]]
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??
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?
I get the following error when trying to build the Android Analytics Snippets
Minimum supported Gradle version is 7.0.2. Current version is 6.5.1.
It appears that this should be updated to build correctly for new users.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.