简体   繁体   English

Android - Clickable Widget - 在模拟器上工作,但不在手机上

[英]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.

相关问题 android调试可用于手机,但不能与模拟器一起使用 - android debugging is working with phone but not with emulator 在模拟器上工作但不在Android手机上工作的方法 - Method working on emulator but not on an android phone Android小部件在模拟器中运行良好,但在手机上它变成了Google App小部件 - Android widget works well in emulator but on phone it turns into the Google App widget Android Geolocation 在模拟器中工作但在手机中不起作用 - Android Geolocation working in emulator but not working in phone 引导接收器可在模拟器上运行,但不能在Android实际手机上运行 - Boot Reciever Working on Emulator but not android actual phone android中的图像捕获仅在手机中的模拟器上有效 - Image capturing in android is working only on emulator not in phone Android-SMS BroadcastReceiver在模拟器上运行,但不在电话上运行 - Android - SMS BroadcastReceiver Working on Emulator but Not on Phone Android-服务器请求在模拟器上工作,但不能在电话上工作 - Android - Server requests working on emulator but not on phone android:联系人提供程序在模拟器中工作,但不在电话上 - android: Contacts provider working in emulator but not on phone 在模拟器上工作但在真正的 android 手机上工作的代码 - Code working on emulator but not on real android phone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM