Wednesday, October 5, 2016

Library (jar) creation with androidstudio

There are two way in android to create library project first use project with whole source code with plugin type library in gradle and second create jar file.

Both type has their different uses regarding application requirement.
In eclipse it is very simple just check islibrary project option in add library section and you can generate library project but for android studio it is different way to create library project.

Here is the steps to create jar file using android studio and also same project can be added as a library module without generating jar .


1) Create a project.

2) open file build.gradel of module level

3) change one line in build.gradel module level:
apply plugin: 'com.android.application' -> apply plugin: 'com.android.library'

4) remove applicationId in the module level build.gradel file .

applicationId "com.mycomp.testproject"

5) build project
Build > ReBuild Project

6) then you can get aar file
app > build > outputs > aar folder

7) change aar file extension name into zip

8) unzip, and you can see classes.jar in the folder.
rename with your library name with this jar and use it!

Wednesday, August 31, 2016

Android Standard Icon Sizes

Android application development require standard application icon with different sizes to handle multiple screen-size for different devices.
below is the standard images sizes :  
mdpi (Baseline): 160 dpi 1×
hdpi: 240 dpi 1.5×
xhdpi: 320 dpi 2×
xxhdpi: 480 dpi 3×
xxxhdpi: 640 dpi 4× (launcher icon only)
Launcher icons (.Png images)
48 × 48 (mdpi)
72 × 72 (hdpi)
96 × 96 (xhdpi)
144 × 144 (xxhdpi)
192 × 192 (xxxhdpi)
512 × 512 (Google Play store)
Action bar, Dialog & Tab icons
24 × 24 area in 32 × 32 (mdpi)
36 × 36 area in 48 × 48 (hdpi)
48 × 48 area in 64 × 64 (xhdpi)
72 × 72 area in 96 × 96 (xxhdpi)
96 × 96 area in 128 × 128 (xxxhdpi)*
Notification icons
22 × 22 area in 24 × 24 (mdpi)
33 × 33 area in 36 × 36 (hdpi)
44 × 44 area in 48 × 48 (xhdpi)
66 × 66 area in 72 × 72 (xxhdpi)
88 × 88 area in 96 × 96 (xxxhdpi)*
Small Contextual Icons
16 × 16 (mdpi)
24 × 24 (hdpi)
32 × 32 (xhdpi)
48 × 48 (xxhdpi)
64 × 64 (xxxhdpi)*
 Most of the cases developer does not put all images and app will work because usually android picks drawable from other folder and most of cases that works also, 
but it is a good practice to having all icon and images with standard size and places.

Thursday, July 21, 2016

SMS READER IN ANDROID


SMS READER IN ANDROID:

Now a days many application providing functionality for SMS. In android programming we can implement this functionality with the below permission permissions

<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

Below example code can be copied from here in desired application and It can read all inbox as well as it updates SMS when new SMS comes on user device.

We can develop whole messaging apps if we want make that functionality to part of our application like few apps providing that functionality to make their apps as a default messenger app.
Here is SMS reader example

Android manifest permission:

<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<activity
    android:name=".SmsActivity"
    android:label="@string/app_name" >
   <!-- <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

<receiver android:name=".SmsBroadcastReceiver" android:exported="true" >
    <intent-filter android:priority="999" >
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>



XML implementation  (activity_sms.xml):


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/MainLayout"
    android:weightSum="1"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="SMS Inbox"
        android:id="@+id/textView"
        android:layout_gravity="center_horizontal"
       />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".15">

        <ListView android:id="@+id/SMSList"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_margin="5dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".85"
        android:gravity="center_horizontal">


        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:text="Report"
            android:textColor="@color/white"
            android:background="@color/darkVoilet"
            android:id="@+id/btn_report"
            android:layout_gravity="center"/>
    </LinearLayout>

</LinearLayout>


values / Colors.xml  :


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>

        <color name="lightVoilet">#ccccff</color>
    <color name="darkVoilet">#944dff</color>
    <color name="white">#ffffff</color>
</resources>


Activity Class  - SmsActivity.java :
 
 
package com.example.com.testapp;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class SmsActivity extends AppCompatActivity implements OnItemClickListener,View.OnClickListener {

    private static SmsActivity inst;
    ArrayList<String> smsMessagesList = new ArrayList<String>();
    ListView smsListView;
    ArrayAdapter arrayAdapter;
    Button btn_report;

    public static SmsActivity instance() {
        return inst;
    }

    @Override
    public void onStart() {
        super.onStart();
        inst = this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sms);
        btn_report=(Button)findViewById(R.id.btn_report);
        btn_report.setOnClickListener(this);
        smsListView = (ListView) findViewById(R.id.SMSList);
        arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, smsMessagesList);
        smsListView.setAdapter(arrayAdapter);
        smsListView.setOnItemClickListener(this);

        refreshSmsInbox();
    }

   /*
   Coloum details for SMS reader
    olumn ID    –   Column Name

    0                      :      _id
    1                      :     thread_id
    2                      :     address
    3                      :     person
    4                      :     date
    5                      :     protocol
    6                      :     read
    7                      :    status
    8                      :    type
    9                      :    reply_path_present
    10                   :    subject
    11                   :    body
    12                   :    service_center
    13                   :    locked*/

    public void refreshSmsInbox() {
        ContentResolver contentResolver = getContentResolver();
        Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"), null, null, null, null);
        int indexBody = smsInboxCursor.getColumnIndex("body");
        int indexAddress = smsInboxCursor.getColumnIndex("address");
        if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
        arrayAdapter.clear();
        do {
            String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
                    "\n" + smsInboxCursor.getString(indexBody) + "\n";
            arrayAdapter.add(str);
        } while (smsInboxCursor.moveToNext());
    }

    public void updateList(final String smsMessage) {
        arrayAdapter.insert(smsMessage, 0);
        arrayAdapter.notifyDataSetChanged();
    }

    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        try {
            String[] smsMessages = smsMessagesList.get(pos).split("\n");
            String address = smsMessages[0];
            String smsMessage = "";
            for (int i = 1; i < smsMessages.length; ++i) {
                smsMessage += smsMessages[i];
            }

            String smsMessageStr = address + "\n";
            smsMessageStr += smsMessage;
            Toast.makeText(this, smsMessageStr, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.btn_report:

        }
    }


}


Broadcast receiver – SmsBroadcastReceiver :

package com.example.com.testapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsBroadcastReceiver extends BroadcastReceiver {

    public static final String SMS_BUNDLE = "pdus";

    public void onReceive(Context context, Intent intent) {
        Bundle intentExtras = intent.getExtras();
        if (intentExtras != null) {
            Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
            String smsMessageStr = "";
            for (int i = 0; i < sms.length; ++i) {
                SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

                String smsBody = smsMessage.getMessageBody().toString();
                String address = smsMessage.getOriginatingAddress();

                smsMessageStr += "SMS From: " + address + "\n";
                smsMessageStr += smsBody + "\n";
            }
            Toast.makeText(context, smsMessageStr, Toast.LENGTH_SHORT).show();

            //this will update the UI with message
            SmsActivity inst = SmsActivity.instance();
            inst.updateList(smsMessageStr);
        }
    }
}


I have write here only for reader code making few changes sms writing functionality can be implemented.











SMS READER IN ANDROID


SMS READER IN ANDROID:

Now a days many application providing functionality for SMS. In android programming we can implement this functionality with the below permission permissions

<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

Below example code can be copied from here in desired application and It can read all inbox as well as it updates SMS when new SMS comes on user device.

We can develop whole messaging apps if we want make that functionality to part of our application like few apps providing that functionality to make their apps as a default messenger app.
Here is SMS reader example

Android manifest permission:

<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<activity
    android:name=".SmsActivity"
    android:label="@string/app_name" >
   <!-- <intent-filter>
        <action android:name="android.intent.action.MAIN" />

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

<receiver android:name=".SmsBroadcastReceiver" android:exported="true" >
    <intent-filter android:priority="999" >
        <action android:name="android.provider.Telephony.SMS_RECEIVED" />
    </intent-filter>
</receiver>



XML implementation  (activity_sms.xml):


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/MainLayout"
    android:weightSum="1"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="SMS Inbox"
        android:id="@+id/textView"
        android:layout_gravity="center_horizontal"
       />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".15">

        <ListView android:id="@+id/SMSList"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_margin="5dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".85"
        android:gravity="center_horizontal">


        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:text="Report"
            android:textColor="@color/white"
            android:background="@color/darkVoilet"
            android:id="@+id/btn_report"
            android:layout_gravity="center"/>
    </LinearLayout>

</LinearLayout>


values / Colors.xml  :


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>

        <color name="lightVoilet">#ccccff</color>
    <color name="darkVoilet">#944dff</color>
    <color name="white">#ffffff</color>
</resources>


Activity Class  - SmsActivity.java :
 
 
package com.example.com.testapp;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class SmsActivity extends AppCompatActivity implements OnItemClickListener,View.OnClickListener {

    private static SmsActivity inst;
    ArrayList<String> smsMessagesList = new ArrayList<String>();
    ListView smsListView;
    ArrayAdapter arrayAdapter;
    Button btn_report;

    public static SmsActivity instance() {
        return inst;
    }

    @Override
    public void onStart() {
        super.onStart();
        inst = this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sms);
        btn_report=(Button)findViewById(R.id.btn_report);
        btn_report.setOnClickListener(this);
        smsListView = (ListView) findViewById(R.id.SMSList);
        arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, smsMessagesList);
        smsListView.setAdapter(arrayAdapter);
        smsListView.setOnItemClickListener(this);

        refreshSmsInbox();
    }

   /*
   Coloum details for SMS reader
    olumn ID    –   Column Name

    0                      :      _id
    1                      :     thread_id
    2                      :     address
    3                      :     person
    4                      :     date
    5                      :     protocol
    6                      :     read
    7                      :    status
    8                      :    type
    9                      :    reply_path_present
    10                   :    subject
    11                   :    body
    12                   :    service_center
    13                   :    locked*/

    public void refreshSmsInbox() {
        ContentResolver contentResolver = getContentResolver();
        Cursor smsInboxCursor = contentResolver.query(Uri.parse("content://sms/inbox"), null, null, null, null);
        int indexBody = smsInboxCursor.getColumnIndex("body");
        int indexAddress = smsInboxCursor.getColumnIndex("address");
        if (indexBody < 0 || !smsInboxCursor.moveToFirst()) return;
        arrayAdapter.clear();
        do {
            String str = "SMS From: " + smsInboxCursor.getString(indexAddress) +
                    "\n" + smsInboxCursor.getString(indexBody) + "\n";
            arrayAdapter.add(str);
        } while (smsInboxCursor.moveToNext());
    }

    public void updateList(final String smsMessage) {
        arrayAdapter.insert(smsMessage, 0);
        arrayAdapter.notifyDataSetChanged();
    }

    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        try {
            String[] smsMessages = smsMessagesList.get(pos).split("\n");
            String address = smsMessages[0];
            String smsMessage = "";
            for (int i = 1; i < smsMessages.length; ++i) {
                smsMessage += smsMessages[i];
            }

            String smsMessageStr = address + "\n";
            smsMessageStr += smsMessage;
            Toast.makeText(this, smsMessageStr, Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.btn_report:

        }
    }


}


Broadcast receiver – SmsBroadcastReceiver :

package com.example.com.testapp;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsBroadcastReceiver extends BroadcastReceiver {

    public static final String SMS_BUNDLE = "pdus";

    public void onReceive(Context context, Intent intent) {
        Bundle intentExtras = intent.getExtras();
        if (intentExtras != null) {
            Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
            String smsMessageStr = "";
            for (int i = 0; i < sms.length; ++i) {
                SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

                String smsBody = smsMessage.getMessageBody().toString();
                String address = smsMessage.getOriginatingAddress();

                smsMessageStr += "SMS From: " + address + "\n";
                smsMessageStr += smsBody + "\n";
            }
            Toast.makeText(context, smsMessageStr, Toast.LENGTH_SHORT).show();

            //this will update the UI with message
            SmsActivity inst = SmsActivity.instance();
            inst.updateList(smsMessageStr);
        }
    }
}


I have write here only for reader code making few changes sms writing functionality can be implemented.











Monday, July 4, 2016

CSV file read and write in android

CSV WRITE AND READ IN ANDROID

There are many time in android programmers needs to write CSV or export few reports, data in csv format. There are many open source third party libraries available to do this but for the same you can write code without using any third party library.

According to my observation it is better Idea to write own code instead of using third party library like Opencsv libs etc. Generally library is designed to perform multiple task and for the same lots of code used inside library and our requirement is only to read or write csv file then why should we increase our code size to using library.

There is a simple way to read and write CSV without any third party library:


1)      Create a directory to write file

File folder = new File(Environment.getExternalStorageDirectory()
        + "/TestFolder");

boolean var = false;
if (!folder.exists())
    var = folder.mkdir();

System.out.println("" + var);


String fileName = folder.toString() + "/" + "Test.csv";



2)      Writing a CSV file

  FileWriter writer = new FileWriter(fileName);

 writer.append("DisplayName");
 writer.append(',');
 writer.append("Age");
 writer.append('\n');

 writer.append("RAM");
 writer.append(',');
 writer.append("21");
 writer.append('\n');

 writer.append("ROHAN");
 writer.append(',');
 writer.append("22");
 writer.append('\n');


3)      Read CSV file

String []data ;

   FileInputStream fis = new FileInputStream(file);


   BufferedReader r = new BufferedReader(new InputStreamReader(fis));


   while ((strLine = r.readLine()) != null)   {


                                  dataValue = line.split(",");


                                         String first = dataValue[1];


     String second = dataValue[2];
        }
   r.close();



Using the above code snippet user can read and write csv files below is whole function for the same.



public void generateCsvFile()
{
    try
    {

        File folder = new File(Environment.getExternalStorageDirectory()
                + "/ TestFolder ");

        boolean var = false;
        if (!folder.exists())
            var = folder.mkdir();

        System.out.println("" + var);


        String fileName = folder.toString() + "/" + "Test.csv";

//Here logic can be write to arrange required format of data
        FileWriter writer = new FileWriter(fileName);

        writer.append("DisplayName");
        writer.append(',');
        writer.append("Age");
        writer.append('\n');

        writer.append("RAM");
        writer.append(',');
        writer.append("26");
        writer.append('\n');

        writer.append("ROHAN");
        writer.append(',');
        writer.append("29");
        writer.append('\n');

        writer.flush();
        writer.close();

    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
}








Wednesday, May 25, 2016

Optimize power consumption in android app development

Optimize power consumption in android app

For mobile application development it is compulsory that application should not consume more power. In order to provide end users with good battery performance, device manufacturers have a joint responsibility together with all of app developers. Now a day’s mobile operating system provides whole and sole solution for user. User doesn’t need to use their laptops or PCs for small works like e-mail, documents reading etc.

I am sharing few programming things that should be taken care by developer to develop an application with minimum power consumption.

Reducing Network Battery Drain

The network traffic generated by an app can have a significant impact on the battery life of the device where it is running. In order to optimize that traffic, you need to both measure it and identify its source.

 In order to properly optimize your app's use of networking resources, you must understand how frequently your app is using the network and for what reasons.

Analyze how much network traffic use in android application and try to reduce the same for example Wi-Fi network consume less power instead of mobile data therefore if you have some downloading secondary task that can be allow to download in Wi-fi network only.

Use network only when you required do not make unnecessary call in application that request continuously in network with server.

Always optimize background services that should not be continuously running without necessary task.

Network Traffic Tool:

The Network Traffic tool in Android Studio helps you see how your app uses network resources in real time.

To start the Network Traffic tool and visualize the network requests:
1.       Start the Network Traffic tool by launching Android Studio and choosing Tools > Android > Android Device Monitor. When asked, allow incoming network connections.
2.       In the Android Device Monitor window, click the DDMS button along the top and choose the Network Statistics tab. If you don't see this tab, widen the window and then try Window > Reset Perspective.
3.       Select your app to debug from the list of debuggable apps on your device in the Devices tab, then click the Start button in the Network Statistics tab.
  

Optimizing for Doze and App Standby

Doze mode from android 6.0 and higher can affect you application for power reduction therefore at the time of development must test your app with Doze mode and optimize your app.

Doze and App Standby manage the behavior of all apps running on Android 6.0 or higher, regardless whether they are specifically targeting API level 23. To ensure the best experience for users, test your app in Doze and App Standby modes and make any necessary adjustments to your code.

Doze can affect apps differently. You must optimize the way that your app manages network, alarms, jobs, and syncs. Apps should be able to efficiently manage activities during each maintenance window.

Way to test android app with doze mode:

1.       Configure a hardware device or virtual device with an Android 6.0 or higher system image.
2.       Connect the device to your development machine and install your app.
3.       Run your app and leave it active.
4.       Shut off the device screen. (The app remains active.)
5.       Force the system to cycle through Doze modes by running the following commands:

$ adb shell dumpsys battery unplug
$ adb shell dumpsys deviceidle step

You may need to run the second command more than once. Repeat it until the device state changes to idle.

6.       Observe the behavior of your app after you reactivate the device. Make sure the app recovers gracefully when the device exits Doze.

Monitoring the Battery Level and Charging State

The battery-life impact of performing application updates depends on the battery level and charging state of the device. 

In some cases it's also useful to determine the current battery level. You may choose to reduce the rate of your background updates if the battery charge is below a certain level.

Optimize application code for background task or network access according to certain battery limit it make application more smooth and reduce the chance of data lose.

Monitoring the Docking State and Type

Android devices can be docked into car or home, digital and analog docks. Docking state means generally your charging state.

You may choose to increase the update frequency of a sports center app when it's in the desktop dock, or disable your updates completely if the device is car docked. Conversely, you may choose to maximize your updates while car docked if your background service is updating traffic conditions.

Determine docking state:

Register receiver:
IntentFilter ifilter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
Intent dockStatus = context.registerReceiver(null, ifilter);

Extract the current docking status from the EXTRA_DOCK_STATE extra

int dockState = battery.getIntExtra(EXTRA_DOCK_STATE, -1);
boolean isDocked = dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED;

Monitoring the Connectivity Status

 Most of the android application repeating alarms and background services is to schedule regular updates of application data from Internet resources. It might be possible that there is no network or network is very slow to download data in that case network should be monitored and should not run scheduler it is completely meaningless as well as consume power of device.