put a new message into inbox and then device manage it - android

i have an android program, in which i receive a message from the database at the external server on web then i put message in SMS inbox.
now i use system notification like this :
Notification intent :
ctx = context ;
notificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
syncNotification = new Notification();
notificationIntent = new Intent(Intent.ACTION_MAIN,null);
notificationIntent.setComponent(new ComponentName("com.android.mms","com.android.mms.ui.ConversationList"));
notificationIntent.addFlags(Notification.FLAG_AUTO_CANCEL);
contentIntent = PendingIntent.getActivity(ctx, 0,
notificationIntent, 0);
Notification creation :
syncNotification.icon = android.R.drawable.stat_notify_chat;
syncNotification.tickerText = ctx.getText(R.string.new_message);
syncNotification.when = System.currentTimeMillis();
syncNotification.setLatestEventInfo(ctx, ctx.getText(R.string.new_message), ctx.getText(R.string.check_your_inbox),contentIntent);
notificationManager.notify(5, syncNotification);
and then play sms ringtone:
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(ctx, notification);
r.play();
after receive message and put it into inbox, notification shown but when i tap it nothing done.
are there a way that after inserting message to inbox, device show default notification and manage it ?

in android api 14 and later it is not possible because google prevent .

Related

Need to add facebook App like notifications in my app

[Facebook notification list]I need to add Facebook app like notifications List into my app,
My app will generate posts and those are submitted to the servers,
any comments added onto any post will into the applications .
So i need to create one notification list like facebook with relative
time elapsed , which shows list of notifications like
"Ragav commented on post no-24, 6 mins ago" .
Can any one help me to how could i make notification list like Facebook, what things need to be there to create notification list ?
Thank You !
See the image , I was asking about this .
use webview and in webview use SSE html5 and get the data from webview.
HTML5 SSE
How to get webview content
This is a library you can use to get relative time text, to get 6 min ago, just now etc
https://github.com/curioustechizen/android-ago
GCM (Google cloud Messaging).you can generate push notification wherever you need.
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
private static void generateNotification(Context context, String message) {
// int notifyID = 1;
int smallIcon = R.drawable.toreachmelight_blue;
int requestID = (int) System.currentTimeMillis();
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context,
AutoReceivenotifiation.class);
Date d = new Date();
int uniqueID = d.getSeconds();
notificationIntent.putExtra("shareloc_name", group_name);
// context.startActivity(notificationIntent);
/*
* notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP |
* Intent.FLAG_ACTIVITY_NEW_TASK);
*/
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
context, requestID, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context);
mBuilder.setSmallIcon(smallIcon)
.setAutoCancel(true)
.setTicker(type)
.setContentTitle("ToReachMe")
.setContentText(Html.fromHtml("<u>" + type + "<u>"))
.setWhen(when)
.setContentIntent(pendingNotificationIntent)
.setDefaults(
Notification.DEFAULT_LIGHTS
| Notification.DEFAULT_VIBRATE)
.setSound(
Uri.parse("android.resource://"
+ context.getPackageName() + "/" + R.raw.beep));
notificationManager.notify((int) uniqueID, mBuilder.build());
}

Notification sound not playing

I know this question has been asked many times, but I'm still having issues getting it working.
In my application, I create a notification to prompt the user of some event and I'd like to play a sound that has been packaged as a raw resource within the application.
I create my notification instance:
Notification notification = new Notification(
R.drawable.some_image,
"some meaningful name",
System.currentTimeMillis() );
notification.setLatestEventInfo(...)
Then set some attributes on that notification:
notification.sound = Uri.parse( "android.resource://com.my.package/" + R.raw.some_mp3_file );
notification.flags = Notification.FLAG_INSISTENT;
Finally I invoke the NotificationManager to display the notification:
notificationManager.notify( 1, notification );
The notification does shows up, but the sound doesn't play.
Am I doing something wrong? Is there a <uses-permission> I'm missing? I can't see anything that I've done differently from anyone else that seems to have gotten it working.
For what it's worth, I'm testing directly on a Nexus 7.
try to look at below code. may help you out to solve your problems.
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.update;
CharSequence tickerText = "assignments";
long when = System.currentTimeMillis();
Notification assignmentNotification = new Notification(icon, tickerText, when);
**For sound** assignmentNotification.defaults |= Notification.DEFAULT_SOUND;
long[] vibrate = {0,100,200,300};
**For vibrate** assignmentNotification.vibrate = vibrate;
Context context = getApplicationContext();
CharSequence contentTitle = "check assignments";
CharSequence contentText = "chek ur app for assignments ";
Intent notificationIntent = new Intent(context, ViewAssignmentnotificationActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,0);
assignmentNotification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
** final int id = 2;
Please see this answer; It tells you that you have to explicitly specify notification.sound to play that tone;

Does anyone know how to impose counters on status bar notifications in Honeycomb

I am trying to use number field of Notification class to get "number of events" associated with each notification. For Ex. If I have two unread emails, email icon in the status bar should show "2" imposed on the email icon. I think this was working fine with froyo but somehow I am not able to make it work for Honeycomb. This is how my code looks like
PendingIntent contentIntent;
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
Notification.Builder builder = new Notification.Builder(this);
builder.getNotification().number = 2;
builder.setSmallIcon(R.drawable.phone_missedcall);
builder.setTicker("ABCD & Status : Missed Call");
notificationIntent = new Intent (this, NotificationSBActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
builder.setContentIntent(contentIntent);
contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.contact_image, R.drawable.ic_contact_picture);
contentView.setTextViewText(R.id.line_name, "Line 2: Cisco");
builder.setContent(contentView);
But it doesn't show "2" imposed over the icon. Is there any other way to get the counter in Honeycomb ??
Also, tried
int icon = R.drawable.phone_app; // icon from resources
CharSequence tickerText = "Hello"; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = "My notification"; // message title
CharSequence contentText = "Hello World!"; // message text
notificationIntent = new Intent(this, NotificationSBActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.number = 2;
mNotificationManager.notify(0, notification);
Please let me know if anyone has tried notification counters on Honeycomb ??

Updating new notification

I am using following code to get notifications from a service
nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this,test.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent,Notification.FLAG_AUTO_CANCEL);
String body = "Hi this is test"+count;
String title = "Ritu"+count;
Notification n = new Notification(R.drawable.icon,body,System.currentTimeMillis());
n.setLatestEventInfo(this, title, body, pi);
n.defaults = Notification.DEFAULT_LIGHTS;
n.number=++count;
nm.notify(uniqueid, n);
Every time I am getting a new notification, the number on it gets incremented but when I open notification window I can see only one the latest notification and after clicking on it number of notification does not get decremented.
Where I am wrong please help.
Thanks!
Try this, in order to remove notification after click:
n.flags |= Notification.FLAG_AUTO_CANCEL;
And instead of using:
n.number = ++count;
Use:
count++;
nm.notify(count, n);
This will allow you to have multiple notifications at the same time
Follow this like if u can get help...
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/NotifyWithText.html

Android Unable to launch the Inbox from a notification

I have the following code that creates a notification when an SMS message is received by the phone. It displays the notification correctly; however, when the user clicks the notification, nothing happens. It should open up the SMS inbox so the user can view their message. Thanks in advance.
mNotificationManager = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
Uri uri = Uri.parse("content://sms/inbox");
PendingIntent contentIntent = PendingIntent.getActivity(arg0, 0, new Intent(Intent.ACTION_VIEW, uri), Intent.FLAG_ACTIVITY_NEW_TASK);
String tickerText = arg0.getString(R.string.newmsg, msgs[i].getMessageBody().toString());
Notification notif = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis());
notif.setLatestEventInfo(arg0, msgs[i].getOriginatingAddress(), msgs[i].getMessageBody().toString(), contentIntent);
notif.vibrate = new long[] { 100, 250, 100, 500 };
mNotificationManager.notify(R.string.recv_msg_notif_id, notif);
I got it to work. The following code shows how to accomplish this task:
Intent notificationIntent = new Intent(Intent.ACTION_MAIN);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.setType("vnd.android-dir/mms-sms");

Categories

Resources