how to create a Big text notification in android studio

how to create a Big text notification in android studio. when user has more then one line of text then big text type notification are used  

Big text notification

Collapse view of big text 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: get text from edit text or set your own text into notification call this method on button click Set Summary Text and title that you want 

public void N5_bigtextnotification(View view) {

        stile = txttitle.getText().toString().trim();
        smessage = txtmessage.getText().toString().trim();

        Bitmap largeicon = BitmapFactory.decodeResource(getResources(), R.drawable.image);

        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(largeicon);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText("chgfh ffyu tyuyuiyuf rsdtdy           rttyff tr yrty yry y ry yrty  gghggu  u uuy uuu uhfghcg gf ghfghfhjf h hf hfhjf ghfyfyf yfyf        yfvuhjv fhgfhj hjghjv gfx hgjhgvcxujhcyuhbc hgffc hj ghg ")
         .setBigContentTitle("Bit title").setSummaryText("Bandi ke messages"));
        builder.setPriority(NotificationCompat.PRIORITY_HIGH);


        NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
        notificationManagerCompat.notify(1, builder.build());


    }

step 4: get text from edit text or set your own text into notification call this method on button click

 public void N3_actionbtnnotification(View view) {

        stile = txttitle.getText().toString().trim();
        smessage = txtmessage.getText().toString().trim();

        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);


        Intent bordcastreciver_intent = new Intent(this, BroadcastReceiver.class);
        bordcastreciver_intent.putExtra("message", stile);
        PendingIntent ActionIntent = PendingIntent.getBroadcast(this, 0, bordcastreciver_intent, PendingIntent.FLAG_UPDATE_CURRENT);

        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.setContentIntent(pendingIntent);
        builder.addAction(R.mipmap.ic_launcher, "Reply", ActionIntent);  // use your own button icon and text you want 
        builder.setAutoCancel(true);
        builder.setOnlyAlertOnce(true);
        builder.setColor(Color.BLUE);
        builder.setPriority(NotificationCompat.PRIORITY_HIGH);


        NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
        notificationManagerCompat.notify(1, builder.build());

    }

Thank You Keep Learning Keep Connected #AndroidShortCode

Comments