0

We have developed a device and an application (native Android) for smart phone. The device communicates data via Bluetooth Low Energy into the phone where the application processes the data. Some users would like to use the system all the time over long periods of time, even weeks. The data transmission into the phone should be continuous without breaks. In tests with Samsung Galaxy A5 (2017) that has android OS 6.0.1, it has turned out that the system works fine for hours. But when the application is running over longer periods of time, phone's operating system tends to stop the application. Occasionally, only the Bluetooth is stopped. In older phone models and OS 5, e.g. Galaxy S4, such problems do not occur. Is there any way to protect the application in such a way that it is not stopped?

Timo
  • 1

2 Answers2

0

In android OS 6 and upper you must to ask runtime permission, maybe that is the problem. Add bellow code on your project

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_files);

    ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.BLUETOOTH},
                1);

      //..your code...
}

@Override
public void onRequestPermissionsResult(int requestCode,
                                   String permissions[], int[] grantResults) 
{
switch (requestCode) {
    case 1: {

      // If request is cancelled, the result arrays are empty.
      if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            // contacts-related task you need to do.          
        } else {

            Toast.makeText(MainActivity.this, "Permission denied", Toast.LENGTH_SHORT).show();
        }
        return;
    }
}

}

Fakhriddin Abdullaev
  • 4,169
  • 2
  • 35
  • 37
  • Project already has the code for asking the permission. Permission is granted. – Timo Jun 02 '17 at 09:10
  • Did you request the permission explicitly? because starting Android API 23 you need to request permission to the user. – GGWP Jun 02 '17 at 10:21
0

It depends if the phone has a pre-installed or normally installed battery saving app that kills background operations for a long period of time. Take this app for example

GGWP
  • 1,111
  • 2
  • 12
  • 24