【问题标题】:Taking photo from camera and setting that image in notification icon in android从相机拍照并在 android 的通知图标中设置该图像
【发布时间】:2014-08-11 11:46:31
【问题描述】:

我想将我的相机图片设置为通知图标

这是我的主要活动

intent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);

.......................

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK){
extras=data.getExtras();
bmp=(Bitmap) extras.get("data");
imageView.setImageBitmap(bmp);
}
}

我正在尝试从我的广播接收器获取位图

public void onReceive(Context context, Intent intent) {
///////////////////////////................
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("image");
 Notification notification2=new Notification.Builder(context).setTicker(from)
              .setContentTitle(from)
              .setSmallIcon(R.drawable.ic_launcher)
              .setLargeIcon(bitmap)
              .setContentText(message).setContentIntent(contentIntent)
              .addAction(0,"remind",contentIntent).build();

但这不起作用我正在强制停止:(

【问题讨论】:

  • 我也试过 Bitmap bitmap = (Bitmap) intent.getParcelableExtra("image");资源 res = context.getResources(); int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height); int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);位图 = Bitmap.createScaledBitmap(位图,宽度,高度,假); //////////////........ .setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(bitmap) ////........ ..但仍然出现错误
  • 如果您能提供一些错误消息的输出,帮助您会容易得多。就像 logcat 输出一样。

标签: android notifications icons


【解决方案1】:

如果您遇到错误

E/JavaBinder﹕ !!! FAILED BINDER TRANSACTION !!!

这是由于位图对于 Android Binder 来说太大(我相信它的限制为 1 MB)。在尝试将图像传递到 Bundle 之前,您应该先查看压缩图像。看看这个帖子:Failed binder transaction when putting an bitmap dynamically in a widget

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 2016-11-19
    • 1970-01-01
    相关资源
    最近更新 更多