1

I'm programming a widget. When somebody clicks on the widget Button, the Flashlight is turning on. If you click again on the widget button, the Flashlight is turning off. I wrote a small app, there its works, because i have a surface view in my layout xml file. On my widget xml that is not working.

This is my widget_layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<SurfaceView
    android:id="@+id/surface"
    android:layout_width="1dp"
    android:layout_height="1dp" />

<ImageButton
    android:id="@+id/button"
    android:src="@drawable/off"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_centerInParent="true"
    android:scaleType="center"/>

</FrameLayout>

On the developer Page, there is a text:

http://developer.android.com/guide/topics/appwidgets/index.html

A RemoteViews object (and, consequently, an App Widget) can support the following layout classes:

FrameLayout
LinearLayout
RelativeLayout
GridLayout

And the following widget classes:

AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
ViewFlipper
ListView
GridView
StackView
AdapterViewFlipper

So my widget button will never work, because i can't use surface view.

user1205415
  • 605
  • 1
  • 7
  • 22
  • How can i add Surface View in widget_layout.xml? So it works with the widget button. – user1205415 Sep 16 '12 at 21:34
  • 1
    user1205415, There is no way to make it. RemoteViews accept only a strictly defined set of Views. You gotta wait for future Android versions, hoping that the SurfaceView will get in this set once. – Egor Sep 17 '12 at 06:25

1 Answers1

4

You need to pass a dummy surface texture instead of a surface view.....for example:

Add this to turnLightOn code:

mCamera.setPreviewTexture(new SurfaceTexture(0));