【发布时间】:2014-01-02 20:35:07
【问题描述】:
我想在拖放后将我的小部件安装到我的主页,但是当我这样做时,它说应用程序无法安装这里是我的代码:
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Intent receiver = new Intent(context, WidgetReceiver.class);
receiver.setAction("COM_FLASHLIGHT");
receiver.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, receiver, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.Button, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
}
还有我的提供商信息:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="40dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:previewImage="@drawable/more"
android:initialLayout="@layout/widget_layout"
android:configure="com.flashlight.standroid.WidgetProvider"
android:resizeMode="horizontal|vertical"
android:label="Monitor Widget">
</appwidget-provider>
我的清单:
<receiver
android:name=".WidgetProvider"
android:icon="@drawable/more"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.example.flash.ACTION_WIDGET_RECEIVER" />
<action android:name="android.appwidget.action.APPWIDGET_ENABLED" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/provider_info" />
</receiver>
<receiver
android:name="WidgetReceiver">
<intent-filter>
<action android:name="com.flashlight"></action>
</intent-filter>
</receiver>
在这里,我收集了几乎所有用于运行/安装的代码部分。我的小部件。提前致谢
【问题讨论】:
-
确切的错误信息是什么?
-
“它说”——什么是“它”?如果“它”不是 LogCat,LogCat 中会显示哪些警告或错误?
-
在我的手机上,它出现在小部件上,但是当我尝试将它拖放到我的主屏幕上时,我的手机显示“应用程序未安装”
-
请发布您的清单,尤其是定义
com.flashlight.standroid.WidgetProvider的部分。对于Activity,这将是一个相当奇怪的名称。 -
请查看我最近的编辑
标签: java android android-widget widget installation