Android 我的应用程序小部件';s Remoteview';s接收器随机接听电话
我是应用程序小部件的初学者。在这里,我制作了一个app的小部件,在它的类中,单击小部件图标设置receiver。当用户单击它时,它就会工作。但问题是receiver有时也会被自动调用。 我不明白为什么会发生这样的事情。我们将非常感谢您的帮助 我的应用程序小部件的类: MyWidget.java:Android 我的应用程序小部件';s Remoteview';s接收器随机接听电话,android,broadcastreceiver,android-widget,android-pendingintent,appwidgetprovider,Android,Broadcastreceiver,Android Widget,Android Pendingintent,Appwidgetprovider,我是应用程序小部件的初学者。在这里,我制作了一个app的小部件,在它的类中,单击小部件图标设置receiver。当用户单击它时,它就会工作。但问题是receiver有时也会被自动调用。 我不明白为什么会发生这样的事情。我们将非常感谢您的帮助 我的应用程序小部件的类: MyWidget.java: public class MyWidget extends AppWidgetProvider { static Context cont; static SharedPreferen
public class MyWidget extends AppWidgetProvider {
static Context cont;
static SharedPreferences preferences;
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
preferences = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
cont = context;
Intent intent2 = new Intent(context, MyReceiver.class);
PendingIntent pendingIntent = PendingIntent.
getBroadcast(context, 0,
intent2, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.my_widget);
views.setOnClickPendingIntent(R.id.appwidget_text, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
}
@Override
public void onEnabled(Context context) {
preferences = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
preferences.edit().putBoolean("key", true).commit();
}
@Override
public void onDisabled(Context context) {
preferences = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
preferences.edit().putBoolean("key", false).commit();
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="*************************">
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:roundIcon="@drawable/logo"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Home">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".Myservice" />
<receiver android:name=".MyReceiver"></receiver>
<receiver android:name=".MyWidget">
<intent-filter>
<action android:name="**********************" />
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/my_widget_info" />
</receiver>
</application>
</manifest>
发布您的manifest@DavidWasser-我添加了清单文件..请检查..查看您的_info.xml文件。你有updatePeriodMillis:“XXX”调用。@Kram-我已经在updatePeriodMillis中给出了“86400000”。但它仍然随机调用我的remoteview的click listener的接收器。有人对此有答案吗?