2013-09-29 83 views
0

我一直在尝试创建一个基本的应用窗口小部件,无法将它显示在窗口小部件列表中。Android JAVA Widget没有显示在窗口小部件列表中

代码如下:

Widget_layout.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_margin="8dip" 
> 

<TextView 
    android:id="@+id/update" 
    style="@android:style/TextAppearance.Medium" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:resizeMode="horizontal|vertical" 
    android:gravity="center_horizontal|center_vertical" 
    android:layout_margin="4dip" 
    android:text="@string/click_to_configure" > 
</TextView> 
</LinearLayout> 

Widget_info.xml:

<?xml version="1.0" encoding="utf-8"?> 
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" 
android:minHeight="72dp" 
android:minWidth="146dp" 
android:updatePeriodMillis="1000" 
android:initialLayout="@layout/widget_layout" 
android:resizeMode="horizontal|vertical" 
android:initialKeyguardLayout="@layout/widget_layout" 
android:widgetCategory="keyguard|home_screen" 
android:configure="com.promethylhosting.countdowntowidget.SettingsActivity" 
/> 

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.promethylhosting.countdowntowidget" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk 
    android:minSdkVersion="15" 
    android:targetSdkVersion="17" /> 

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 


<activity 
    android:name=".SettingsActivity" 
    android:icon="@drawable/ic_launcher" 
    android:label="Countdown to... Widget"> 
     <intent-filter> 
      <action android:name=".ACTION_WIDGET_CONFIGURE"/> 

     </intent-filter> 

    <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     <!-- mulitple actions must have multiple action filters 1:1 ratio between  action/filter --> 
    </activity> 

    <reciever 
     android:name="CountdownToWidgetProvider" 
     android:icon="@drawable/ic_launcher" 
     android:label="Countdown To Widget"> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 
     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_info" /> 
    </reciever> 
</application> 
</manifest> 

我一直在使用Google周围,没有找到任何解决方案解决了这个问题。所以我在这里张贴。

非常感谢您阅读本文和建议。

编辑:其他建议?

+0

任何其他的想法有问题吗? – mcollard

回答

0

在主要活动试试这个,总是有显示部件在4.0

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
     sendBroadcast(new Intent(Intent.ACTION_MAIN) 
     .addCategory(Intent.CATEGORY_HOME)); 
    setContentView(R.layout.main); 



} 

清单还参考here

+0

我有这个代码目前在主要/发射器: 尝试sendBroadcast(新意图(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)); (LOG_TAG,“尝试激活小部件,我得到...某事:”+ e.getMessage()); } – mcollard

+0

有没有其他建议可以使这项工作? – mcollard

相关问题