here is the code I use to set a notification for any event. But my requirement is, Instead of just only text I also want to display a picture in the notification panel, which is not a logo, a complete picture (or may be cropped). How to modify this code to get this work done.
Secondly, my notification does it job properly,but when there are too many text to display, it does not expands. Is there any way to make a notification expandable.
Thirdly, some portion of my code, you will see that, those commands are deprecated( when I am initiating the notification and also at notification.setLatestInfo()). So, what is the right way to write it, and if I write it would it work on lower version as well? thanks in advance.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ok = (Button) findViewById(R.id.dones);
et = (EditText) findViewById(R.id.ets);
ok.setOnClickListener(MainActivity.this);
counter = getSharedPreferences("count", 0);
notificationId = counter.getInt("val", 0);
}
@SuppressWarnings("deprecation")
@Override
public void onClick(View arg0) {
String Text = et.getText().toString();
if(Text.equals("")){
Toast.makeText(getApplicationContext(), "You Don't have anything to clip", Toast.LENGTH_SHORT).show();
}
else{
notification = new Notification(R.drawable.ic_launcher, "You Got Things ToDo!", System.currentTimeMillis());
notificationmanager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent pending = PendingIntent.getActivity(this, 0, new Intent(this,MainActivity.class), 0);
notification.setLatestEventInfo(getApplicationContext(), "I want to ..", Text, pending);
notificationmanager.notify(notificationId, notification);
notificationId++;
notification.flags |= Notification.FLAG_NO_CLEAR;
}
}
You should check out
Notification.Builder
, particularlysetStyle()
:http://developer.android.com/reference/android/app/Notification.Builder.html
and then
Notification.BigPictureStyle
should allow you to show an image like you desire:http://developer.android.com/reference/android/app/Notification.BigPictureStyle.html
Edited with code sample, since you're processing the Bitmap as well, I've added an AsyncTask so that the processing doesn't occur on the UI thread: