Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by test test
at 2026-09-30 13:11:09
Point:500 Replies:3 POST_ID:829440USER_ID:12446
Topic:
android;java;javascript
as title , please advise
the following is from google search:
package com.yourpackage.name;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String CHANNEL_ID = "image_notification_channel";
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
// Check if message contains a data payload
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
String title = data.get("title");
String body = data.get("body");
String imageUrl = data.get("imageUrl");
// Download image if URL exists
Bitmap bitmap = null;
if (imageUrl != null && !imageUrl.isEmpty()) {
bitmap = getBitmapFromUrl(imageUrl);
}
showNotification(title, body, bitmap);
}
}
// Helper method to download image from the network URL
private Bitmap getBitmapFromUrl(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private void showNotification(String title, String body, Bitmap bitmap) {
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Create Notification Channel for API 26+ (Oreo)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Image Notifications",
NotificationManager.IMPORTANCE_DEFAULT
);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification) // Replace with your app's notification icon
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true);
// If image download succeeded, style the notification
if (bitmap != null) {
builder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap)
.bigLargeIcon((Bitmap) null)); // Hides thumbnail when expanded
builder.setLargeIcon(bitmap); // Shows thumbnail when collapsed
}
if (notificationManager != null) {
// Use a unique ID or a timestamp if you want multiple notifications to stack
notificationManager.notify((int) System.currentTimeMillis(), builder.build());
}
}
}
Expert: rcschroeder replied at 2026-09-30 13:34:49
**Sending User Image URL from Firebase Data Notification on Android Java**
In this example, we will demonstrate how to send a user's image URL from Firebase Data Notification to an Android app using Java.
**Step 1: Add Firebase SDK to Android Project**
Firstly, add the Firebase SDK to your Android project. Add the following dependencies to your `build.gradle` file:
```groovy
dependencies {
implementation 'com.google.firebase:firebase-messaging:22.0.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
}
```
**Step 2: Create Firebase Data Notification**
To send data notifications from Firebase, create a Firebase Data Notification in the Firebase Console. Here's how:
1. Go to the Firebase Console and select your project.
2. Navigate to the "Notifications" tab.
3. Click on the "+" icon to create a new notification.
4. Enter a title, message, and image URL.
5. Click on the "Save" button.
**Step 3: Send Notification from Firebase**
To send the notification from Firebase, use the Firebase SDK. Here's an example of how to send a notification:
```java
// Send data notification
HashMap<String, String> data = new HashMap<>();
data.put("title", "Notification Title");
data.put("body", "Notification Body");
data.put("imageUrl", "https://example.com/user-image.jpg");
Map<String, String> payload = new HashMap<>();
payload.put("data", data.toString());
RemoteMessage remoteMessage = new RemoteMessage.Builder("your_topic")
.setNotification(data)
.setPayload(payload)
.build();
FirebaseMessaging.getInstance().send(remoteMessage);
```
**Step 4: Handle Notification in Android App**
In the Android app, handle the notification in the `onMessageReceived` method:
```java
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
// Check if message contains a data payload
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
String title = data.get("title");
String body = data.get("body");
String imageUrl = data.get("imageUrl");
// Download image if URL exists
Bitmap bitmap = null;
if (imageUrl != null && !imageUrl.isEmpty()) {
bitmap = getBitmapFromUrl(imageUrl);
}
showNotification(title, body, bitmap);
}
}
```
**Step 5: Download and Display Image**
To download and display the image, use the following helper method:
```java
private Bitmap getBitmapFromUrl(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
```
**Step 6: Display Notification**
To display the notification, use the following method:
```java
private void showNotification(String title, String body, Bitmap bitmap) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Create Notification Channel for API 26+ (Oreo)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Image Notifications",
NotificationManager.IMPORTANCE_DEFAULT
);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification) // Replace with your app's notification icon
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true);
// If image download succeeded, style the notification
if (bitmap != null) {
builder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap)
.bigLargeIcon((Bitmap) null)); // Hides thumbnail when expanded
builder.setLargeIcon(bitmap); // Shows thumbnail when collapsed
}
if (notificationManager != null) {
// Use a unique ID or a timestamp if you want multiple notifications to stack
notificationManager.notify((int) System.currentTimeMillis(), builder.build());
}
}
```
This is a basic example of how to send user image URL from Firebase Data Notification to an Android app using Java.
In this example, we will demonstrate how to send a user's image URL from Firebase Data Notification to an Android app using Java.
**Step 1: Add Firebase SDK to Android Project**
Firstly, add the Firebase SDK to your Android project. Add the following dependencies to your `build.gradle` file:
```groovy
dependencies {
implementation 'com.google.firebase:firebase-messaging:22.0.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
}
```
**Step 2: Create Firebase Data Notification**
To send data notifications from Firebase, create a Firebase Data Notification in the Firebase Console. Here's how:
1. Go to the Firebase Console and select your project.
2. Navigate to the "Notifications" tab.
3. Click on the "+" icon to create a new notification.
4. Enter a title, message, and image URL.
5. Click on the "Save" button.
**Step 3: Send Notification from Firebase**
To send the notification from Firebase, use the Firebase SDK. Here's an example of how to send a notification:
```java
// Send data notification
HashMap<String, String> data = new HashMap<>();
data.put("title", "Notification Title");
data.put("body", "Notification Body");
data.put("imageUrl", "https://example.com/user-image.jpg");
Map<String, String> payload = new HashMap<>();
payload.put("data", data.toString());
RemoteMessage remoteMessage = new RemoteMessage.Builder("your_topic")
.setNotification(data)
.setPayload(payload)
.build();
FirebaseMessaging.getInstance().send(remoteMessage);
```
**Step 4: Handle Notification in Android App**
In the Android app, handle the notification in the `onMessageReceived` method:
```java
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
// Check if message contains a data payload
if (remoteMessage.getData().size() > 0) {
Map<String, String> data = remoteMessage.getData();
String title = data.get("title");
String body = data.get("body");
String imageUrl = data.get("imageUrl");
// Download image if URL exists
Bitmap bitmap = null;
if (imageUrl != null && !imageUrl.isEmpty()) {
bitmap = getBitmapFromUrl(imageUrl);
}
showNotification(title, body, bitmap);
}
}
```
**Step 5: Download and Display Image**
To download and display the image, use the following helper method:
```java
private Bitmap getBitmapFromUrl(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
```
**Step 6: Display Notification**
To display the notification, use the following method:
```java
private void showNotification(String title, String body, Bitmap bitmap) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Create Notification Channel for API 26+ (Oreo)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"Image Notifications",
NotificationManager.IMPORTANCE_DEFAULT
);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification) // Replace with your app's notification icon
.setContentTitle(title)
.setContentText(body)
.setAutoCancel(true);
// If image download succeeded, style the notification
if (bitmap != null) {
builder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(bitmap)
.bigLargeIcon((Bitmap) null)); // Hides thumbnail when expanded
builder.setLargeIcon(bitmap); // Shows thumbnail when collapsed
}
if (notificationManager != null) {
// Use a unique ID or a timestamp if you want multiple notifications to stack
notificationManager.notify((int) System.currentTimeMillis(), builder.build());
}
}
```
This is a basic example of how to send user image URL from Firebase Data Notification to an Android app using Java.
Author: test test replied at 2026-09-30 13:12:30
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Author: test test replied at 2026-09-30 13:11:46
<service
android:name=".MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>