MainActivity.java
import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.app.NotificationCompat; import android.view.View; import android.widget.Button; import java.util.Calendar; public class MainActivity extends AppCompatActivity { Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) findViewById(R.id.idBtn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ClickMe(); } }); } private void ClickMe() { //To set large icon in notification 3 Bitmap icon1 = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); //Assign BigText style notification NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); bigText.bigText("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."); bigText.setBigContentTitle("Big Text Notification"); bigText.setSummaryText("By: Author of Lorem ipsum"); //build notification NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("Big Text notification") .setContentText("This is test of big text style notification.") .setLargeIcon(icon1) .setStyle(bigText); // Gets an instance of the NotificationManager service NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //to post your notification to the notification bar mNotificationManager.notify(0, mBuilder.build()); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="anu.com.notification.MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/idBtn" android:background="#FFCC65" android:text="Click" /> </RelativeLayout>
EmoticonEmoticon