7

に、私はにonUpdateでウィジェットのレイアウトに画像表示で画像を設定しようとしていますが、画像はウィジェット画像はウィジェット

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imgView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

マニフェストファイルの

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.demo.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".WidgetConfig" 
      android:label="@string/app_name" > 
      <intent-filter> 
        <action 
        android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> 
      </intent-filter> 
     </activity> 
     <receiver 
      android:name="BasicWidgetProvider"> 
      <intent-filter> 
       <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
      </intent-filter> 
      <meta-data 
       android:name="android.appwidget.provider" 
       android:resource="@xml/widget_info" /> 
     </receiver> 

      <receiver 
      android:name="BasicWidgetProvider"> 
      <intent-filter> 
       <action 
        android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
        <data android:scheme="widget" /> 
      </intent-filter> 
      <meta-data 
       android:name="android.appwidget.provider" 
       android:resource="@xml/widget_info" /> 
     </receiver> 
    </application> 

@Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) 
    { 
     Log.i(TAG, "onUpdate called"); 
     for (int appWidgetId : appWidgetIds) 
     { 
      Bitmap bitmap=ImageUtils.getBitmap(context, appWidgetId); 
      RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget); 

      remoteView.setImageViewBitmap(R.id.imgView,bitmap); 
      appWidgetManager.updateAppWidget(appWidgetId, remoteView); 
     } 
    } 

のxmlレイアウトを更新していません

widget_info.xml

<appwidget-provider 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="25dp" 
    android:minHeight="25dp" 
    android:initialLayout="@layout/widget" 
    android:configure="com.demo.WidgetConfig" 
    android:widgetCategory="home_screen|keyguard" 
    android:previewImage="@layout/widget" 
    android:resizeMode="horizontal|vertical" 
    android:initialKeyguardLayout="@layout/widget" 
    android:minResizeHeight="5dp" 
    android:minResizeWidth="5dp"> 
</appwidget-provider> 

しかし、ウィジェットをロードしようとすると、トースト「アプリがインストールされていません。」、私はどこからこのようなトーストを見せていませんか?

なぜ画像が設定されていない、どのように修正するのですか?

+0

をインポートするには、画像なしでロードしていますか?私にとっては、イメージではなくウィジェット/アプリの設定が間違っているようです。マニフェストを投稿できますか? – Gustek

+0

私はマニフェストファイルを追加しました。コード –

答えて

1

は、あなたが設定され、正しいパッケージ名を持っていることを確認しappwidget・プロバイダXMLのフィールドを、そしてまた、あなたは正しいintetnフィルタは、マニフェストファイルに設定されています。

+0

を参照してください。更新コード –

+0

ウィジェットプロバイダーxmlはレイアウトではありません。 – JoxTraex

+0

ok、私は問題のコメントのために投稿し、同じことを言った、同じことを言った、それは大丈夫、私の悪い、再び更新する –

0

以下のように、remoteview.setimageViewuriで試してください。 「アンドロイド:設定」

@Override 
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 

     remoteViews = new RemoteViews(context.getPackageName(), R.layout.main); 
     thisWidget = new ComponentName(context, HelloWidget.class); 
     remoteViews.setImageViewUri(R.id.imageView1,Uri.parse("/mnt/sdcard/test.png")); 
     appWidgetManager.updateAppWidget(thisWidget, remoteViews); 
    } 
0
<receiver 
    android:name="BasicWidgetProvider"> 
    <intent-filter> 
     <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
    </intent-filter> 
    <meta-data 
     android:name="android.appwidget.provider" 
     android:resource="@xml/widget_info" /> 
</receiver> 

名前の前にドットがありません。この受信者は2回お持ちです。

0

このリンクをクリックしてください。ここ
は、ウィジェット Click Here のための完全なデモであり、このプロジェクトcom.javatechig.widgetdemo

+0

[リンクのみの回答はお勧めできません](http://meta.stackoverflow.com/tags/link-唯一の回答/情報)であるので、SOの回答は解決策の検索の終点でなければなりません(時間の経過とともに古くなる傾向にある参照の途中停止)。リンクを参考にして、ここにスタンドアロンの概要を追加することを検討してください。 – kleopatra