此代码必须帮助您
public class CreateNotificationActivity extends AppCompatActivity {
private NetworkImageView mNetworkImageView;
private ImageLoader mImageLoader;
Bitmap bit;
String url = "http://www.whitegadget.com/attachments/pc-wallpapers/145032d1392006652-nature-wallpaper-nature-picture.jpg";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_notification);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mNetworkImageView = (NetworkImageView) findViewById(R.id.networkImageView1);
//bit = BitmapFactory.decodeResource(getResources(), R.drawable.bgd);
//Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bgd);
mImageLoader = CustomVolleyRequestQueue.getInstance(this.getApplicationContext())
.getImageLoader();
Bitmap bitmap =mImageLoader.get(url, ImageLoader.getImageListener(mNetworkImageView,
R.mipmap.ic_launcher, R.drawable.icon)).getBitmap();
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createNotification();
}
});
}
@Override
protected void onStart() {
super.onStart();
mImageLoader = CustomVolleyRequestQueue.getInstance(this.getApplicationContext())
.getImageLoader();
bit =mImageLoader.get(url, ImageLoader.getImageListener(mNetworkImageView,
R.mipmap.ic_launcher, R.drawable.icon)).getBitmap();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void createNotification()
{
bit = BitmapFactory.decodeResource(getResources(), R.drawable.bgd);
mImageLoader.get(url, new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer imageContainer, boolean b) {
bit =mImageLoader.get(url, ImageLoader.getImageListener(mNetworkImageView,
R.mipmap.ic_launcher, android.R.drawable
.ic_dialog_alert)).getBitmap();
Intent intent = new Intent(getApplicationContext(),NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), (int) System.currentTimeMillis(), intent, 0);
Notification noti = new Notification.Builder(getApplicationContext())
.setContentTitle("Mail Notification")
.setContentText("5 new unread messages")
.setSmallIcon(R.drawable.bgd)
.setStyle(new Notification.BigPictureStyle().bigPicture(bit))
.setAutoCancel(true)
.setContentIntent(pIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0,noti);
Log.i("LOG>>>>>>>>>>>>>>>>>>>","inside the on response");
}
@Override
public void onErrorResponse(VolleyError volleyError) {
bit = BitmapFactory.decodeResource(getResources(), R.drawable.bgd);
Log.i("LOG>>>>>>>>>>>>>>>>>>>","inside the errror response");
}
});
// bit =mImageLoader.get(url, ImageLoader.getImageListener(mNetworkImageView,
// R.mipmap.ic_launcher, android.R.drawable
// .ic_dialog_alert)).getBitmap();
}
}