Full screen notification like in-coming call in android call app - android

I am working on video call android app.My challenge now is to implement full screen notification similar to android built in Call app when you have in-coming call. Currently Whenever i get a call the notification appears as regular notification if the phone screen is off and heads up if the phone is awake.I want the notification to occupy fullscreen just like the call app.I am using Galaxy S5 to test it.What am i missing here is my code.Thank you in advance.
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("screen", "debugScreen");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
Intent callAcceptIntent = new Intent(this, MyReceiver.class);
callAcceptIntent.setAction("com.videochat.CALL_INTENT");
PendingIntent callAcceptPi = PendingIntent.getBroadcast(this,0,callAcceptIntent,0);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.icon)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setTicker("ticker")
.setFullScreenIntent(pendingIntent, true)
.setOngoing(true)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX)
.addAction(R.drawable.icon, "Reject",callAcceptPi);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Related

Android Notification doesn't show on version 4.2.2

Here is how I show a notification:
Intent resultIntent = new Intent(this, MalwareListActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_white)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setOngoing(true)
.setContentIntent(pi)
.build();
mNotificationManager.notify(NOTIFY_ID, notification);
It works find on Android 5.1 but doesn't on v4.2.2.
On v4.2.2 device (I use OPPO R831K), the notification show and hide immediately.
Do I make anything wrong?

Android Push notification is not working on Model number- vs450pp having version 4.4.2

I am getting push notification on Android phone on given model number but when I clicked on the notification, It disappear and doesn't open app. I would be grateful If anyone get me out from that problems.
Try Following Code May be work for you .
Intent intent = new Intent(this, MainActivity.class); //define your application activity name which you want to open.
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Application Title")
.setContentText(message)
.setContentIntent(pIntent)
.setSound(soundUri); //This sets the sound to play
notificationManager.notify(0, mBuilder.build());

Android notification Big View - Intent on button not fired

I'm following the Android Dev tutorial to use Big View for notifications. I want an on going notification with some functionality when clicking on the body of the notification and other functionality when clicking the Button.
This is my code:
Intent bodyIntent = new Intent(context, MainActivity.class);
innerIntent.putExtra(NOTIFICATION_BODY, "Click on notification body");
PendingIntent bodyPendingIntent = PendingIntent.getActivity(context, 0, bodyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent buttonIntent = new Intent(context, MainActivity.class);
buttonIntent.setAction(NOTIFICATION_BUTTON);
PendingIntent buttonPendingIntent = PendingIntent.getService(context, 0, buttonIntent, 0);
android.support.v4.app.NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setCategory(Notification.CATEGORY_SERVICE)
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setContentIntent(notificationPendingIntent)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setLights(getResources().getColor(R.color.primary), 50, 10000)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[] {0, 50})
.setOngoing(true)
.setStyle(new NotificationCompat.BigTextStyle().bigText("Hello World BIG!"))
.addAction(R.mipmap.ic_image, "Button", buttonPendingIntent);
int mNotificationId = 001;
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
Then in onResume:
Intent intent = getIntent();
Log.e("m", String.valueOf(intent.getIntExtra(NOTIFICATION_RESULT, 0)));
Log.e("m", String.valueOf(intent.getAction()));
Result:
When clicking on the body of the notification the bodyIntent fires and I get the correct log printing.
When clicking on the button: Nothing happens and MainActivity not even starting.
Thanks,
You should call PendingIntent.getActivity() method if you want to start an activity, but you are creating buttonPendingIntent by calling PendingIntent.getService().

android push notification not removed when i swipe

android push notification not removed when i swipe
following is my code that i trying to implement push notification
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(icon)
.setContentTitle(title)
.setAutoCancel(true)
.setContentText(message)
.setOngoing(true);
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.putExtra("Your Message", message);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.putExtra("type", type);
notificationIntent.putExtra("id", id);
PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(intent);
notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
can somebody help me to resolve these issue
The .setOngoing(true); should be false, or just remove this line, if you don't put the .setOngoing(boolean) it will be false, so you'll be able to swipe the notification.
More information setOnGoing
Set whether this is an "ongoing" notification. Ongoing notifications cannot be dismissed by the user, so your application or service must take care of canceling them. They are typically used to indicate a background task that the user is actively engaged with (e.g., playing music) or is pending in some way and therefore occupying the device (e.g., a file download, sync operation, active network connection).
So your mBuilder should be like :
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(icon)
.setContentTitle(title)
.setAutoCancel(true)
.setContentText(message)
.setOngoing(false); //or just remove it
The setOngoing makes the notification not dismissible
.setOngoing(true);

Android - How to Display Large Text in Notification

I need to implement a code for displaying large text with 200 characters in Notifications. Here i used following code but it shows single line.
Intent notificationIntent;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.icon)
.setContentTitle(context.getString(R.string.app_name))
.setContentText(message)
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true);
notificationIntent = new Intent(context, Main.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pintent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(pintent);
NotificationManager mNotifyMgr =
(NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(1, mBuilder.build());
You can choose from different styles to use for the notification builder:
In your case I would use the NotificationCompat.BigTextStyle. More details can be found here.
Don't forget to import v4 support when using this.
In my application, notification message is static but can't show all sentense.
I solved with subText properties of notification.
Notification n = new Notification.Builder(this)
.setContentTitle("Job Tracker Application")
.setContentText("GPS is turned off.")
.setSubText("Please turn on in the settings.")
.setSmallIcon(R.drawable.app_icon)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build();
Another notification sample have show under the blogs.
http://www.objc.io/issue-11/android-notifications.html
https://capdroid.wordpress.com/tag/android-notification/
http://www.tutorialspoint.com/android/android_notifications.htm
You add a style for the the large text.
Notification notification = new NotificationCompat.Builder(this, CHANNEL_SYNC)
.setContentTitle(title)
.setSmallIcon(R.drawable.ic_sync)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setColor(getResources().getColor(R.color.colorPrimaryLight))
.setContentIntent(pendingIntent)
.build();

Categories

Resources