小部件导致“应用程序未安装”错误
我正在尝试为主屏幕创建我的第一个Widget。 我已经阅读了开发者网站上的教程,梳理了网络上的教程,tipps和问题解决方案,但似乎无法使其发挥作用。
问题:
我可以运行应用程序没有任何问题。 我也可以从菜单中选择我的应用的Widget(长按主屏幕 - > Android-Widgets - >可用Widgets列表)。 当我选择我的小部件时,我收到以下错误消息(作为敬酒):“应用程序未安装在您的手机上。”
在这里我的源代码 :
进入清单:
<receiver android:name=".SubscriberStateWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/subscriber_status_widget" />
</receiver>
AppWidgetInfoProvider xml:
<?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="300000"
android:configure="de.xxx.SubscriberStateWidgetProvider">
</appwidget-provider>
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/subscriberStateWidgetImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/acc_app_logo"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_margin="5dp" />
<TextView
android:id="@+id/subscriberStateWidgetTextViewLable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subscriberStatusText"
android:layout_toRightOf="@+id/subscriberStateWidgetImage"
android:layout_alignTop="@+id/subscriberStateWidgetImage"
android:layout_marginLeft="5dp"/>
<TextView
android:id="@+id/subscriberStateWidgetTextViewInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/subscriberStateWidgetImage"
android:layout_below="@+id/subscriberStateWidgetTextViewLable"
android:layout_alignBottom="@+id/subscriberStateWidgetImage"
android:layout_marginLeft="5dp"
android:text="@string/subscriberStatusUnknown"/>
</RelativeLayout>
</FrameLayout>
的AppWidgetProvider - 克拉斯:
public class SubscriberStateWidgetProvider extends AppWidgetProvider{
public String SUBSCRIBER_WIDGET_UPDATE = "subscriberWidgetUpdate";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
}
}
}
我已排除的可能原因:
我也尝试在应用程序运行时(启动应用程序,按下按钮以转到主屏幕)以及应用程序未运行(启动应用程序,使用后退按钮停止应用程序)并在两次获得相同行为时尝试创建小部件。
LogCat或我的日志文件中没有错误或警告条目。
我会真正appriciate任何想法,解决方案或帮助你可能有。 提前致谢!
终于得到它的工作:-)仍然不确定,虽然问题是......
这是我的工作源代码:
进入清单:
<receiver android:name="SubscriberStateWidgetProvider" >
<intent-filter >
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/subscriber_status_widget" />
</receiver>
AppWidgetInfoProvider xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/subscriber_state_widget_layout"
android:minHeight="72dp"
android:minWidth="300dp"
android:updatePeriodMillis="300000" >
</appwidget-provider>
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/myshape" >
<TextView
android:id="@+id/subscriberStateLable"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/widgetImage"
android:layout_toRightOf="@+id/widgetImage"
android:gravity="center_horizontal|center_vertical"
android:layout_margin="4dip"
android:text="@string/subscriberStatusText" >
</TextView>
<TextView
android:id="@+id/update"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/widgetImage"
android:layout_toRightOf="@+id/widgetImage"
android:gravity="center_horizontal|center_vertical"
android:layout_margin="4dip"
android:text="@string/subscriberStatusUnknown" >
</TextView>
</RelativeLayout>
的AppWidgetProvider级:
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// Get all ids
ComponentName thisWidget = new ComponentName(context,
SubscriberStateWidgetProvider.class);
String currentSubscriberState = SubscriberStatusActivity.getCurrentSubscriberStateAsString(context);
int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
for (int widgetId : allWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.subscriber_state_widget_layout);
Log.w("WidgetExample", currentSubscriberState);
// Set the text
remoteViews.setTextViewText(R.id.update, currentSubscriberState);
// Register an onClickListener
Intent intent = new Intent(context, SubscriberStateWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.update, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}
链接地址: http://www.djcxy.com/p/50587.html