dongpan8439 2010-09-12 23:38
浏览 35
已采纳

Android小部件在远程视图更新时从模拟器消失

My MySQL DB table holds a BLOB image with image_id as key. I am trying to do the following.

1.HttpPost("http://example.com/RetrieveImage.php") from Android App with the image_id in name value pairs.

The PHP Script is as follows:

<?php
mysql_connect("host","userid","password");
mysql_select_db("database");
$q=mysql_query("SELECT image FROM testblob WHERE image_id =".$_REQUEST['image_id']."");
$e=mysql_fetch_assoc($q);
print($e);
mysql_close();
?>
  1. httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    InputStream is = entity.getContent(); 
    response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
  2. Store the BLOB data in Inputstream object is to byte array

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buf = new byte[10240];
            int n = 0;
            try {
                while ((n=is.read(buf))>=0)
                {
                baos.write(buf, 0, n);
                }
    is.close();
    byte[] bytes = baos.toByteArray();
  3. Convert the byte array to bitmap and set ImageView of the Android widget to the Image

    Bitmap bitmap;
    RemoteViews updateViews = null;
    bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    updateViews = new RemoteViews(context.getPackageName(), R.layout.tuwidget);
    updateViews.setImageViewBitmap(R.id.tuwidget_img_btn, bitmap);
    return updateViews;

Once this is run, I dont know why the widget does not even show up on the emulator and cannot even add the widget anymore to the screen. What am I doing wrong? Any help is much appreciated.

Oh and here is my widget layout.

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tuwidget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/tuwidget_img_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</ImageView>
</AbsoluteLayout>
  • 写回答

2条回答 默认 最新

  • dtp87205 2010-09-15 14:57
    关注

    Got the problem - Bitmap was returning Null so the widget initial layout vanished. Issue was in the php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: