AppWidget аварийно завершает работу программы запуска после завершения настройки sh (только для Xiaomi и Huawei) - PullRequest
0 голосов
/ 20 февраля 2020

Я пытаюсь отобразить AppWidget на устройстве дома. Я не могу понять, почему, только на устройствах Xiaomi и Huawei это не работает.

Когда я перетаскиваю виджет на домашний экран, он приятно открывает мою конфигурационную активность. Я закрываю это действие, используя:

private void saveConfig() {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);

    ComponentName thisAppWidget = new ComponentName(getPackageName(), 
        ConfigActivity.class.getName());

    Intent updateIntent = new Intent(this, ConfigActivity.class);

    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

    updateIntent.setAction(ACTION_APPWIDGET_UPDATE);
    updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

    setResult(RESULT_OK, updateIntent);

    finish();
}

После этого панель запуска кажется глючной: экран становится черным, ящик недавних приложений открыт, я не на той же странице, на которой был ...

В LogCat нет ничего особенного.

Все нормально, другие устройства, такие как Samsung или OnePlus.

У кого-то была похожая проблема?

Манифест. xml

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@drawable/ic_launcher_round"
        android:usesCleartextTraffic="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning"
        tools:targetApi="m">

        <activity
            android:name="com.######.presentation.activity.ConfigActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
            </intent-filter>
        </activity>

       <activity
            android:name=".presentation.activity.HomeActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden"/>

       <activity
            android:name=".presentation.activity.LegalNoticeActivity"
            android:screenOrientation="portrait"
            android:configChanges="orientation|keyboardHidden"/>

       <receiver
            android:name="com.######.provider.EnergyMixWidgetProvider"
            android:icon="@drawable/ic_launcher_round"
            android:label="@string/app_name">
        <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>

    <meta-data
        android:name="android.appwidget.provider"
        android:resource="@xml/appwidget_info" />
    </receiver>

    <receiver android:name=".presentation.receiver.NotificationActionReceiver"/>

    <service android:name=".data.service.ListenerService" />
</application>

appwidget_provider

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
     android:initialKeyguardLayout="@layout/app_widget_4"
     android:initialLayout="@layout/app_widget_4"
     android:minHeight="110dp"
     android:minWidth="250dp"
     android:updatePeriodMillis="0"
     android:resizeMode="horizontal"
     android:widgetCategory="home_screen"
     android:previewImage="@mipmap/ic_launcher"
  android:configure="com.########.presentation.activity.ConfigActivity"/>

Любая помощь будет рада

РЕДАКТИРОВАТЬ Если я удалю действие конфигурации из атрибута android:configure провайдера apwidget, appwidget действительно появится на главном экране. Это позволило мне подумать, что проблема в намерении, отправленном в результате моего действия по настройке

1 Ответ

0 голосов
/ 24 февраля 2020

Вы передаете массив идентификаторов виджетов. Попробуйте изменить код на:

В onCreate добавьте

Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
        AppWidgetManager.INVALID_APPWIDGET_ID);
    }

, затем выполните:

private void saveConfig() {

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ConfigActivity.updateAppWidget(context, appWidgetManager, mAppWidgetId);

    Intent updateIntent = new Intent();
    updateIntent .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
    setResult(RESULT_OK, updateIntent);

    finish();
}
...