0

Суть задачи, на устройстве запустить цикл с обработкой данных

Thread run = new Thread(new Runnable() {
    @Override
    public void run() {
        while (true) {
            try {

                register_position(); // Отдельная функция

                Thread.sleep(5000); // 1000 - 1 сек 
            } catch (InterruptedException ex) {
                break;
            }
        }
    }
});
run.start(); 

Не могу разобраться в чем проблема.

Не запускается BroadcastReceiver

Grable

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "ru.system_gps.assistant"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Манифест

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="ru.system_gps.assistant">

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <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">
        <activity android:name=".Main">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name="ru.system_gps.assistant.SAR.OnBootReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

Ресивер

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class OnBootReceiver extends BroadcastReceiver {

    public OnBootReceiver() {}

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.e("BootReceiver", "On!");
        }

    }
}

Структура проекта

введите сюда описание изображения

Ресивер не выводит в лог сообщение. В чем может быть дело? (Основные действия находятся в Services, хотел запустить сервис через ресивер. Помогити разобраться)

4
  • Это не основной проект, суть этого проекта просто вывод в консоль сообщения. 2 янв 2018 в 18:19
  • А как вы запускаете этот ресивер? Из предоставленного кода увидел, что он просто есть...
    – kulikovman
    3 янв 2018 в 9:06
  • При загрузке устройства <action android:name="android.intent.action.BOOT_COMPLETED" /> он срабатывает 3 янв 2018 в 12:23
  • Вот здесь описаны несколько вариантов, почему это может не работать.
    – kulikovman
    3 янв 2018 в 15:32

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.