I'm trying to implement this train and not getting it. I wanted to do the same thing as the colleague who opened the thread, but I could not even follow these examples.
I have some questions: In what class do I set this Calendar bid? On the receiver itself? from what I understood from the example, it is calling itself in this example of the topic ( topic link ):
Intent tarefaIntent = new Intent(context, ExecutarTarefaProgramadaReceiver.class);
What I would like: I am developing together with facul colleagues, a localization system. The idea is to check from time to time if there is an internet connection. If you have unsent connection and information from our app, then we will send the data to a webservice or anywhere else we imagine. That way I did it, every time I unlock the cell phone screen it just opens the map. (but this is not what I want, as I want the service to remain active and to "wake up (check a condition and if it is true run") execute a method).
Summary:
I would like my service to start at the boot of the phone and stay "listening" until there is an internet connection. When it does, then it does something - in that case it executes a method that I determine (which I also do not know where it should be).
My Receive:
package com.teste.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
import com.teste.MapsActivity;
/**
* Created by Jaquisson on 17/09/2015.
*/
public class TbReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent intent = new Intent(context, MapsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
MyService looks like this:
package com.teste.service;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.os.IBinder;
/**
* Created by Jaquisson-SENAC on 17/09/2015.
*/
public class TbService extends Service {
private BroadcastReceiver receiver;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
//IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
//filter.addAction(Intent.ACTION_SCREEN_OFF);
//filter.addAction(Intent.ACTION_USER_PRESENT);
//receiver = new TbReceiver();
//Log.d("service", "Receiver será iniciado");
//registerReceiver(receiver, filter);
//super.onCreate();
}
}
And below is the excerpt from my manifesto:
<service
android:name=".service.TbService"
android:exported="false" >
</service>
<service
android:name=".BuscaLocalizacao"
android:exported="false" >
</service>
<receiver android:name=".receiver.TbReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
Dude, I've researched in several places and I can not understand how I should do it. I looked at the documentation, but I did not understand either. I'm starting out and a little lost in it.
I'm sorry to post this bunch of stuff, but I'm a bit of a detail.
Thank you.