Я пытаюсь отправить трансляцию с IntentService после загрузки, анализа и записи данных в файл.Мои данные загружаются и сохраняются правильно, и моя трансляция, кажется, отправляет правильно.Однако я не получаю обратный вызов от onReceive в моем классе AppWidgetProvider.
Вот метод onHandleIntent из моего IntentService.Вот откуда отправляется трансляция:
@Override
protected void onHandleIntent(@Nullable Intent intent) {
if(intent.getAction().equals(WeatherWidgetProvider.ACTION_UPDATE_WEATHER)) {
Log.i(TAG, "onHandleWork: Current intent action = " + intent.getAction());
Log.i(TAG, "onHandleWork: Service Started");
createConnection();
if(dataUpdatedSuccessfully) {
Log.i(TAG, "onHandleWork: Sending broadcast");
Intent updateIntent = new Intent();
updateIntent.setAction(WeatherWidgetProvider.ACTION_UPDATE_WEATHER);
updateIntent.addCategory(Intent.CATEGORY_DEFAULT);
sendBroadcast(intent);
}
dataUpdatedSuccessfully = false;
}
else {
Log.i(TAG, "onHandleIntent: Incorrect Action");
}
}
Вот метод onReceive в моем AppWidgetProvider:
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive: Response Received");
String action = intent.getAction();
if(action != null && action.equals(ACTION_UPDATE_WEATHER)) {
Log.i(TAG, "onReceive: Updating Weather");
Toast.makeText(context, "Updating Weather", Toast.LENGTH_SHORT).show();
}
else {
Log.i(TAG, "onReceive: Incorrect action: " + action);
}
super.onReceive(context, intent);
}
А вот манифест:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mack.john.mackjohn_ce03">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true" >
<receiver android:name=".WeatherWidgetProvider" android:exported="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="com.mack.john.ACTION_UPDATE_WEATHER"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/provider_info"/>
</receiver>
<service android:name=".services.DownloadIntentService"/>
</application>