Skip to content

Commit

Permalink
fire
Browse files Browse the repository at this point in the history
  • Loading branch information
banditAmit committed Jul 30, 2023
1 parent aed7fcb commit b0217cf
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ android {


dependencies {

implementation 'com.google.firebase:firebase-storage-ktx:20.2.1'
releaseImplementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
Expand Down
2 changes: 1 addition & 1 deletion app/google-services.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:135771924448:android:9ca06163fa71cf73dbad85",
"mobilesdk_app_id": "1:135771924448:android:57eab34c35a3088fdbad85",
"android_client_info": {
"package_name": "com.BugBazaar"
}
Expand Down
36 changes: 33 additions & 3 deletions app/src/main/java/com/BugBazaar/ui/MyProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.BugBazaar.utils.DeviceDetails;
import com.BugBazaar.R;
import com.google.firebase.FirebaseApp;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

public class MyProfile extends AppCompatActivity {
private FirebaseStorage firebaseStorage;


private static final int SELECT_PHOTO_REQUEST = 1;
private ImageView imageView;
Expand All @@ -26,7 +32,8 @@ public class MyProfile extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_myprofile);

FirebaseApp.initializeApp(this);
firebaseStorage = FirebaseStorage.getInstance();
imageView = findViewById(R.id.imageView);

imageView.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -62,13 +69,36 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten

// Save the image to internal storage
saveImageToInternalStorage(imageBitmap);
uploadImageToFirebaseStorage(selectedImageUri);

} catch (Exception e) {
e.printStackTrace();
}
}
}
}



private void uploadImageToFirebaseStorage(Uri imageUri) {
String device= DeviceDetails.getDeviceName();
// Get a reference to the Firebase Storage location where you want to upload the image
StorageReference storageRef = firebaseStorage.getReference().child(device+"/" + System.currentTimeMillis() + ".png");

// Upload the image
storageRef.putFile(imageUri)
.addOnSuccessListener(taskSnapshot -> {
Log.d("hello","success");
// Image upload successful, do something if needed
})
.addOnFailureListener(exception -> {
Log.d("hello","fail");
// Handle unsuccessful uploads, do something if needed
});
}



private void loadAndDisplayImage() {
try {
String filename = "my_image.png";
Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/com/BugBazaar/utils/DeviceDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.BugBazaar.utils;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;

import java.util.HashMap;
import java.util.Map;

public class DeviceDetails {

public static void initializeFirebase(Context context) {
FirebaseApp.initializeApp(context);
}

public static String getDeviceName() {
String manufacturer = Build.MANUFACTURER;
String model = Build.MODEL;
if (model.startsWith(manufacturer)) {
return capitalize(model);
} else {
return capitalize(manufacturer) + " " + model;
}
}

private static String capitalize(String s) {
if (TextUtils.isEmpty(s)) {
return "";
}
char firstChar = s.charAt(0);
if (Character.isUpperCase(firstChar)) {
return s;
} else {
return Character.toUpperCase(firstChar) + s.substring(1);
}
}

public static String getDeviceId(Context context) {
return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}

}

0 comments on commit b0217cf

Please sign in to comment.