Showing posts from March, 2018

Check the service on several time gaps.

Now three...

Hope this will be very useful for those who doing time intervals and web services.


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

public class ServiceChecker extends BroadcastReceiver {
    ShukranDbHelper dbHelper;
    public void onReceive(Context context, Intent arg1) {
        // Just calling your method
Log.d("hey", "I'm alive");

In AndroidManifest.xml

<receiver android:name=".service.DataChecker"></receiver>

In your Activity, Just call this.

Intent alarmIntent = new Intent(this, ServiceChecker.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, 0);

public void startAlarm() {
    manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    int interval =600000; // 10 minute //10000
    manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);

public void c…

Check Network Using BroadCastReceiver

Hello friends,

Hope you already see this example in lot of websites and blogs. I'm also doing these, because hope my example might be easy and understandable.

Let's go.

Create the class:


public class ConnectivityReceiver extends BroadcastReceiver {

    public static ConnectivityReceiverListener connectivityReceiverListener;

    public ConnectivityReceiver() {

    public void onReceive(Context context, Intent arg1) {
        ConnectivityManager cm = (ConnectivityManager) context
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null
                && activeNetwork.isConnectedOrConnecting();

        if (connectivityReceiverListener != null) {

    public static boolean isConnected() {

Touch Events in Fragment

Hi friends, Have a great day. Today we're going to look for touch events in fragment. Taps - If you gonna multiple tap to view or do something, this will be more helpful.

Just implement TouchListener in your fragment like this,

public class FirstFragment extends Fragment implements View.OnTouchListener


    public boolean onTouch(View v, MotionEvent event) {
        int eventaction = event.getAction();
        if (eventaction == MotionEvent.ACTION_UP) {

            //get system current milliseconds
            long time = System.currentTimeMillis();

            //if it is the first time, or if it has been more than 3 seconds since the first tap ( so it is like a new try), we reset everything
            if (startMillis == 0 || (time - startMillis > 3000)) {
                startMillis = time;
                count = 1;
            //it is not the first, and it has been  less than 3 seconds since the first
            else { //  time-startMillis< 3000