how to create a Big Picture notification in android studio. Big picture notification is mostly used notification when we have image that needed to show to user with notification
![]() |
Collapse view of big picture notification |
![]() |
Big Picture notification |
step :1 create a App class and create an notification channels
public class App extends Application {
public static final String CHANNEL_ID = "channel1";
@Override
public void onCreate() {
super.onCreate();
creatnotificationchannel();
}
private void creatnotificationchannel() {
if (Build.VERSION.SDK_INT >=
Build.VERSION_CODES.O) {
CharSequence name = "personal
notification";
String description = "personal
informaton all are here";
int importance =
NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel
notificationChannel = new NotificationChannel(CHANNEL_ID, name,
importance);
notificationChannel.setDescription(description);
NotificationManager
notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
}
}
}
step :2 add app class into menifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notifiaction">
<application
android:name=".App"
// This is app class
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
step 3: in big picture notification you need to get bitmap of that image and then set into notification . here we are using a resource drawable then convert into bitmap
public void N6_bigpicturenotification(View view) {
Bitmap picture = BitmapFactory.decodeResource(getResources(), R.drawable.image2);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
builder.setContentTitle("this is title of message");
builder.setSmallIcon(R.drawable.ic_notifications_active_black_24dp);
builder.setContentText("This is content text of notification");
builder.setLargeIcon(picture);
builder.setOngoing(false); // if you are using true this notification cancelable by swipe this is always showing
builder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(picture).bigLargeIcon(null));
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setAutoCancel(true);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
notificationManagerCompat.notify(1, builder.build());
}
Comments
Post a Comment