我正在尝试制作主屏幕。我有要显示的小部件,但我需要发送一些通知,所以它将启动。也许我错过了AndroidManifest.xml
中的某些内容?
的AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Fredrik" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HomeScreen" android:label="@string/app_name"
android:launchMode="singleInstance" android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
HomeScreen.java:
public class HomeScreen extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AppWidgetManager widgets = AppWidgetManager
.getInstance(getApplicationContext());
List<AppWidgetProviderInfo> installedProviders = widgets
.getInstalledProviders();
for (AppWidgetProviderInfo ws : installedProviders) {
if (ws.label.startsWith("Music (Large)")) {
AppWidgetHost h = new AppWidgetHost(getApplicationContext(), 10);
int id = h.allocateAppWidgetId();
AppWidgetHostView v= h.createView(this, id, ws);
setContentView(v);
h.startListening();
break;
}
}
}
}
有没有人有线索?
答案 0 :(得分:0)
根据这篇文章,您无法自行编制小部件插入:http://groups.google.com/group/android-developers/browse_thread/thread/e4a5b4a87afcf707?pli=1
您必须调用一个能让用户选择的意图。
我听到你设法让它显示出来后仍然感到惊讶......