Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 小部件图像无法在三星s4安卓4.4设备上更新_Android_Image_Widget - Fatal编程技术网

Android 小部件图像无法在三星s4安卓4.4设备上更新

Android 小部件图像无法在三星s4安卓4.4设备上更新,android,image,widget,Android,Image,Widget,Widget图像不仅在android 4.4三星s4设备上更新,但在其他android 4.1等设备上也可以使用。更新图像是唯一的问题。更新文本没有问题。 问题可能出在setimageviewUri中。 如果你有任何想法,请分享。 谢谢你的帮助 widget's class : enter code here public void onUpdate(Context context, AppWidgetManager appWidgetManager,

Widget图像不仅在android 4.4三星s4设备上更新,但在其他android 4.1等设备上也可以使用。更新图像是唯一的问题。更新文本没有问题。 问题可能出在setimageviewUri中。 如果你有任何想法,请分享。 谢谢你的帮助

widget's class :


enter code here
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                     int[] appWidgetIds) {

    // TODO Auto-generated method stub

super.onUpdate(context, appWidgetManager, appWidgetIds);
resources= context.getResources();
sharedpreferences = context.getSharedPreferences(PREFERENCES,    Context.MODE_PRIVATE);
partnerOneImage=sharedpreferences.getString(partnerOneImageKey,"");
partnerTwoImage=sharedpreferences.getString(partnerTwoImageKey,"");
startDateDay = sharedpreferences.getInt(startDateDayKey, -1);
startDateMonth = sharedpreferences.getInt(startDateMonthKey, -1);
startDateYear = sharedpreferences.getInt(startDateYearKey, -1);
getBackgroundImage = sharedpreferences.getString(backgroundImageKey,"");
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widgetmain3x3);
Intent configIntent = new Intent(context, AddDate.class);
    configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds);  // Identifies the particular widget...
configIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
remoteViews.setImageViewUri(R.id.widget31, Uri.parse(""));
remoteViews.setImageViewUri(R.id.widget31, Uri.parse(partnerOneImage));
remoteViews.setImageViewUri(R.id.widget33, Uri.parse(""));
remoteViews.setImageViewUri(R.id.widget33, Uri.parse(partnerTwoImage));
remoteViews.setTextViewText(R.id.textView3x3, getPassedDays() + " " + resources.getString(R.string.days));
remoteViews.setImageViewUri(R.id.backgroundImage2, Uri.parse(""));
remoteViews.setImageViewUri(R.id.backgroundImage2, Uri.parse(getBackgroundImage));

 PendingIntent configPendingIntent = PendingIntent.getActivity(context,0, configIntent, 0);
 remoteViews.setOnClickPendingIntent(R.id.widget3x3all, configPendingIntent);
 remoteViews.setOnClickPendingIntent(R.id.widget31,configPendingIntent);
 remoteViews.setOnClickPendingIntent(R.id.widget32,configPendingIntent);
 remoteViews.setOnClickPendingIntent(R.id.widget33,configPendingIntent);
 appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);


}

and its xml is `enter code here`


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget3x3all"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:background="@color/white">

<RelativeLayout
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:orientation="horizontal">


<ImageView
android:id="@+id/backgroundImage2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"/>

<ImageView
 android:id="@+id/widget31"
 android:layout_width="100dip"
 android:layout_marginLeft="10dip"
 android:layout_marginTop="10dip"
 android:layout_alignParentLeft="true"
 android:layout_height="100dip"
 android:layout_gravity="right"
 android:clickable="true"
 android:previewImage="@drawable/emptyboy"
 android:scaleType="fitEnd"
 android:textColor="#ffffff" >

 </ImageView>
 <ImageView 
 android:id="@+id/widget32"
 android:layout_width="100dip"
 android:layout_height="100dip"
 android:layout_gravity="right"
 android:clickable="true"
 android:src="@drawable/middleheart1"
 android:scaleType="fitEnd"
 android:textColor="#ffffff"
 android:layout_alignTop="@+id/widget33"
android:layout_centerHorizontal="true">

 </ImageView>


 <ImageView
 android:id="@+id/widget33"
 android:layout_width="100dip"
 android:layout_height="100dip"
 android:layout_marginTop="10dip"
 android:layout_alignParentRight="true"
 android:layout_marginRight="10dip"
 android:clickable="true"
 android:previewImage="@drawable/emptyboy"
 android:scaleType="fitEnd"
 android:textColor="#ffffff" >

 </ImageView>
您必须使用widgetView.setImageViewBitmapR.id.imageid,位图

其中位图为getImageBitmap,请不要忘记检查它是否为空:

其中App.widgetmagecache是WeakHashMap:

public Bitmap getImageBitmap() {
    Uri uri =  getImageUri();
    Bitmap image = null;
    if (App.widgetImageCache.containsKey(uri)) {
        image = App.widgetImageCache.get(uri);
    }
    if (image == null && uri != null) {
        try {
            image = MediaStore.Images.Media.getBitmap(context.getContentResolver(), uri);
            App.widgetImageCache.put(uri, image);
        } catch (IOException e) {
            Log.e(TAG, e);
        }
    }
    return image;
}
public static WeakHashMap<Uri, Bitmap> widgetImageCache = new WeakHashMap<>();