Android JAVA小部件不显示在小部件列表中
我一直在尝试创建一个基本的应用程序小部件,但无法将其显示在小部件列表中 代码如下: Widget_layout.xml:Android JAVA小部件不显示在小部件列表中,java,android,widget,Java,Android,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
<?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>
我一直在谷歌搜索,没有找到任何解决这个问题的方法。所以我在这里发帖
提前感谢您阅读本文和建议
编辑:还有其他建议吗?在您的主要活动中尝试此方法,在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);
}
另请参考一下主/启动器中当前的代码:try{sendBroadcast(newintent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME))}catch(Exception e){Log.wtf(Log_标记,“试图激活小部件,我得到了一些东西:+e.getMessage())}