[英]Android - Clickable Widget - Working on emulator, but not on phone
I tried to create clickable widget on android. 我试图在android上创建可点击的小部件。 I was looking for solution on this site and I found it, but finally this widget is working only on the emulator - not on real phone.
我在这个网站上寻找解决方案而且我找到了它,但最后这个小部件只在模拟器上工作 - 而不是在真正的手机上。 This is my code:
这是我的代码:
AppWidgetProvider: 的AppWidgetProvider:
public static String WIDGET_BUTTON = "apps.test.widget.WIDGET_BUTTON";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.main);
Intent clickIntent = new Intent(WIDGET_BUTTON);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.imageView1, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (WIDGET_BUTTON.equals(intent.getAction())) {
Toast.makeText(context, "asdfsdgdasfg", Toast.LENGTH_SHORT).show();
}
}
Manifest: 表现:
<application
android:allowBackup="true"
android:icon="@drawable/image"
android:label="@string/app_name" >
<receiver
android:name=".Widget"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="apps.test.widget.WIDGET_BUTTON"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/test_widget_provider" />
</receiver>
</application>
Toast is showing up on the emulator but not on phone. Toast出现在模拟器上但不在手机上。
Ok, nevermind. 好吧,那算了。 I had to reset the phone to factory settings.
我不得不将手机重置为出厂设置。 I don't know what was wrong.
我不知道出了什么问题。
This is a common issue,had it a few times with my phone , if the app is installed on sdcard instead of internal storage ,the widget does not appear on the list, you can simply go to Settings->apps->find the app and then select the option to move it to internal storage from your android itself. 这是一个常见的问题,如果我的手机有几次,如果应用程序安装在SD卡而不是内部存储器上,小部件不会出现在列表中,您只需转到设置 - >应用程序 - >找到应用程序然后选择将其从Android本身移动到内部存储的选项。
[ http://www.technipages.com/fix-android-app-widgets-not-appearing-on-widget-list][1] There is another way to declare in the manifest as android:externalstorage(syntax isnt correct) which works as well (I cant find the link though to the answer and I have not tried it) [ http://www.technipages.com/fix-android-app-widgets-not-appearing-on-widget-list][1]还有另一种方法可以在清单中声明为android:externalstorage(语法不正确)这也有效(我找不到答案的链接,我没有尝试过)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.