Hi all,

With new versions of Android, the library needs to be adapted to deal with new possibilities JavocSoft Android Toolbox Libraryand requirements. In this case, the new library JavocSoft Android Toolbox version has resources to handle new Android 6+ Permission system. This will allow us to embrace and adapt our applications to Android 6 new permissions usage approach.

Android 6 and Permissions

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. If the device is running Android 5.1 (API level 22) or lower, or the app’s targetSdkVersion is 22 or lower, the system asks the user to grant the permissions at install time.

System permissions are divided into two categories, normal and dangerous (more info):

  • Normal permissions do not directly risk the user’s privacy. If your app lists a normal permission in its manifest, the system grants the permission automatically. See the list here.
  • Dangerous permissions can give the app access to the user’s confidential data. If your app lists a normal permission in its manifest, the system grants the permission automatically. If you list a dangerous permission, the user has to explicitly give approval to your app. If an app requests a dangerous permission listed in its manifest, and the app already has another dangerous permission in the same permission group, the system immediately grants the permission without any interaction with the user.

See Google Developer Permissions to know more about it.

Adapt your application

To adapt an application to the new permissions usage approach of Android 6+, the application has to be able to deal with these use cases:

  • Start the App. Ask for permission (showing before a message telling why do you need before ask for them)
    • Accept. Ask for permissions:
      • Accept -> App runs normally with the service that requires the permissions.
      • Not accept -> App runs normally without the service that requires the permissions.
    • Cancel. App runs normally without the service that requires the permissions.
  • With previously granted permissions, start the App:
    • Start the App -> App runs normally with the service that requires the permissions.
  • In a running App with granted permissions:
    • Deny the permissions -> When returning to the App, it Asks for permissions (showing before a message telling why do you need before ask for them):
      • Accept. Ask for permissions:
        • Accept -> App runs normally with the service that requires the permissions.
        • Not accept -> App runs normally without the service that requires the permissions.
      • Cancel. App runs normally without the service that requires the permissions.
  • User denies the permission and marks “Never ask again”
    • Start the App:
      • Show a message to the user about the required permissions (showing before a message telling why do you need before ask for them)
        • Accept. Ask for permissions:
          • Accept -> App runs normally with the service that requires the permissions.
          • Not accept -> App runs normally without the service that requires the permissions.
        • Cancel. App runs normally without the service that requires the permissions.

For devices with Android minor than 6 version, API Level 23, you should be able to open the application normally and use it without prompting for any permission because they are already granted when the application is installed.

 

The library JavocSoft Android Toolbox gives you the method to achieve these point in a relative easy way.

Usage

ToolBox provides methods to check for permissions allowing us to present to the user an informative dialog and also ask to allow them if they are not already granted. ToolBox uses the Android Support Library for backward Android compatibility.

The list of functions to handle permissions are:

  • permission_askFor
  • permission_checkAskPermissionsresult
  • permission_isGranted
  • permission_areGranted

ToolBox also provides a set of permissions packages according with Google permissions group. This makes easy for you to ask for permissions for a service that requires a set of permissions.

  • PERMISSION_CALENDAR
  • PERMISSION_CAMERA
  • PERMISSION_LOCATION
  • PERMISSION_MICROPHONE
  • PERMISSION_PHONE
  • PERMISSION_SENSORS
  • PERMISSION_SMS
  • PERMISSION_STORAGE

Here is an example of usage. In this case we are going to use the localization service.

This service requires two permissions that are not automatically granted (not in Google NORMAL permissions group):

  • ACCESS_COARSE_LOCATION
  • ACCESS_FINE_LOCATION

ToolBox has these two permissions in the PERMISSION_LOCATION set. We will use this set to ask for permission to the user:

<!-- Before use it, we check if the permissions are already granted. -->
if(!ToolBox.permission_areGranted(TheActivity.this, ToolBox.PERMISSION_LOCATION.keySet())) {
    //Permissions not yet granted, we need to be ask.
    ToolBox.permission_askFor(TheActivity.this, ToolBox.PERMISSION_LOCATION,     
            ToolBox.PERMISSIONS_REQUEST_CODE_ASK_LOCATION, 
        getString(R.string.permissions_required_title), 
        getString(R.string.permissions_button_ok),
        getString(R.string.permissions_button_deny),
        getString(R.string.permissions_location_required_text));
}else{
     //Permissions are already granted, continue using the localization service...
 
}

To handle the permissions ask response, we must do the following:

<!-- This method handles the response -->
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    permissionsLocationGranted = checkAskPermissionsresult(requestCode, permissions, grantResults);
    Log.i(Constants.TAG, "Location permissions granted? " + permissionsLocationGranted);
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
 
    if(permissionsLocationGranted) {
        //Continue with the usage of the service that needs the permissions...
 
    }else{
        //Do something if required...
    }        
}
 
private boolean checkAskPermissionsresult(int requestCode, String[] permissions, int[] grantResults) {
    boolean res = false;   
    if(requestCode == ToolBox.PERMISSIONS_REQUEST_CODE_ASK_LOCATION) {
            //We could check the permissions in our system
        //res = ToolBox.permission_areGranted(SplashActivity.this, Arrays.asList(permissions));         
            //We check the returned result. Only returns TRUE if all permissions are granted.
        res = ToolBox.permission_checkAskPermissionsresult(permissions, grantResults);
    }
    return res;
}

Have in mind that every time you use a service o function that requires permissions, you should check the current permissions by using:

ToolBox.permission_areGranted(TheActivity.this, ToolBox.PERMISSION_LOCATION.keySet());

To know more about it goto https://github.com/javocsoft/javocsoft-toolbox/wiki#android-6-permissions-handle.

 

Recommended videos about permissions in Android M that you should check:

 

I hope these addition could be useful for your applications.

Do not forget to check the blog to get more updates!

More info and HowTo at https://github.com/javocsoft/javocsoft-toolbox/wiki.

github_icon

As always, library is available on GitHub

javocsoft-toolbox.

Bye.

JavocSoft 2015.

Hi all,

Today a new version of the library JavocSoft Android Toolbox have been released, in this case with a new module that integrates the Google Drive API. This allows to use Android ToolBox - Google DriveGoogle Drive within your applications in a really easy way. I wanted to add this to the library long time ago but until a few weeks i could not start doing it.JavocSoft Android Toolbox Library

To know how to use it and more  goto https://github.com/javocsoft/javocsoft-toolbox/wiki#google-drive.

As a brief, the list of operations that the new module for Google Drive allows are:

  • Create a file (with the posibility of creating it in the secure application folder).
  • Search for files.
  • Get a file given its name or title
  • Get the file contents.
  • Pin a file (this makes Google Drive to store a copy of its metadata locally in the Device).
  • Trash/Un-trash a file.
  • Be notified when a file changes (see TBDrive#addFileChangeListener() and TBChangeListener.java)
  • Subscribe to file changes (notifications are received even if the application is not running. See TBDrive#subscribeToFile() and TBDriveEventService.java).
  • Commit/Discard changes to a file (also be notified when Google Drive servers finish applying changes, see TBDriveEventService.java)
  • Get file contents as an String.
  • Append/Replace text to a file.
  • Get a DriveFile object from an encoded DriveId string.

As always, I hope these addition could be useful for your applications.

Do not forget to check the blog to get more updates!

More info and HowTo at https://github.com/javocsoft/javocsoft-toolbox/wiki.

github_icon

As always, library is available on GitHub

javocsoft-toolbox.

Bye.

JavocSoft 2015.

Google IO 2015 – GCM 3.0

Google I/O 2015

Para los que aún no hayan visto aún esta edición, la 2015, entre las novedades, referente a GCM (Google Clud Messaging), en su versión 3.0, hay una serie de novedades que merecen ser nombradas:

Para no perderte las novedades, si aún no lo viste, haz clic en Google I/O 2015 – Google Cloud Messagin 3.0. Tenéis también la web https://developers.google.com/cloud-messaging en donde poder ver todo lo relativo a GCM.

Como siempre, poco a poco iré integrando estas novedades en la librería Android javocsoft-toolbox, para que podáis disfrutar de dichos cambios de una manera sencilla.

 

Os dejo los videos, a modo recopilatorio, del evento ya pasado.

Y aquí otras exposiciones sobre temas concretos:

 

Un saludo,

Hi all,

I am still finishing the Maps integration and other things to the JavocSoft Android Toolbox Library while preparing some documentation related to GCM and a few HowTos (you can read anyway the Wiki on GitHub) but meanwhile, i have added some useful animation methods that i would JavocSoft Android Toolbox Librarylike to share :).

The new stuff is:

  • Apply animations from one activity to another by using: animation_applyAnimationToActivityLoad().
  • Apply animations to a View by using new methods animation_getFromAnimResourceId() and animation_applyAnimationTo().
  • A set of predefined animations ready to use in your projects. Complete list:
    • Blinking: blink
    • Zooming: zoom_in.xml, zoom_out.xml, zoom_out_in.xml.
    • Curtain: curtain_up.xml , curtain_down.xml, curtain_down_and_bounce.xml, curtain_left_and_right.xml, curtain_right_and_left.xml,
    • Fade: fadein.xml, fadeout.xml,
    • Directions: left_in, left_out, right_in, right_out.
    • Pushing: push_down_in, push_down_out,
    • Rotate: rotate_left_and_right.xml, rotate_right_and_left.xml, rotate_left.xml, rotate_right.xml,
    • Sliding: slide_out.xml, slide_up.xml,
    • Others: bottom_in, move.

 

As always, I hope these changes could help you a bit more than before.

Do not forget to check the blog to get the Maps integration update!

More info and HowTo at https://github.com/javocsoft/javocsoft-toolbox/wiki.

github_icon

As always, library is available on GitHub

javocsoft-toolbox.

Bye.

JavocSoft 2015.

 

Hi all,

Finally i have finished with the last changes in JavocSoft Android Toolbox Library and it is ready on the GitHub repository!. As a brief:

  • There is more functionallity through a lot of new methods.
  • Notifications have been updated to last Android code 5.0+. NotificationCompat is used so now, all posibilities of a notification are implemented (actions, progress bar, priority, visibility and more).
  • GCM Module is updated with the new notifications posibilities allowing to customize more the notifications.

I am still preparing Google Maps v2 integration to put a map in your application with a few lines of code, i hope i can put more time in this to finish it.

JavocSoft Android Toolbox Library

I put here the detailed changes:

  • ToolBox, Notifications:
    • Finally, migrated to NotificationCompat builder 🙂
    • Now the notification title, ticker, content info and large icon can be customized.
    • Priority and visibility implemented, for Android 5.0+ API Level 21+.
    • Implemented big style expandable notification for Android 4.1+ (API Level 16+).
    • Implemented notification actions for Android 4.1+ (API Level 16+).
    • Implemented, for Android 4.0 API Level 14+, notification progress bar (determinate & indeterminate).
    • A new class ToolBox.NotificationProgressBarRunnable has to be extended to create your own long term process.
    • Implemented RemoteViews in notifications.
    • Method notification_generate is maintained for backwards compatibility (it uses also NotificationCompat).
    • New method notification_create that allow to customize completely a notification.
  • ToolBox, Added some more utility methods:
    • device_getOSCodename
    • device_getExtraInfo
    • application_packageName
    • application_packageInfo
    • application_nameInfo
    • application_certificates
    • random_HASH
    • random_UUID
    • random_getRandom
    • random_getSecureRandom
    • gson_linkedMapAsList
    • storage_readRawResource
    • storage_readAssetResource
    • media_getDrawableFromRaw
    • media_getBitmapFromResourceId
    • media_getBitmapFromAsset
    • media_getBitmapFromRaw
    • media_getBitmap (looks, in order, for the resource in Drawable -> Assets -> Raw -> URL)
    • Some media methods to get bytes from a resource image.
  • GCM Module now supports:
    • All ToolBox notification changes. Note: Priority is set to DEFAULT and visibility to PRIVATE.
    • Customization parameters (all these parameters should be set in the data object when delivering the notification to
      the devices in GCM) are:

      • notificationId
      • notStyle
      • title
      • message
      • ticker
      • contentInfo
      • bsTitle
      • bsContent
      • bsSummary
      • bsImage
      • bsInboxStyleContent
      • bsInboxStyleLineSeparator
      • bslargeIcon
  • Added a new TextView component (widget) that allows to show HTML tags.
  • Added a JSON Gson proccesor instance. It gives you a singleton with pre-configured gson processor for a normal process, and, if desired, the possibility of use an excluding “transient” attribute JSON processor and also one excluding properties without the Exposed annotation.
  • Added official PRNG Fix class to Android with API level minor or equal to 18 (Jelly Bean) for JCA or OpenSSL PRNG.
  • BUGFIX. In some devices (depending also of Android version) the flip effect runs laggy. Added a a new flipTransition method that allows to specify to check if the current device is one of reported laggy devices (like LG G3 or Nexus 5). In case is a laggy device, depending of the parameter “enableFadeForLaggyDevices” a fade effect is used as animation instead the desired flip or no effect is applied if set to FALSE.
  • BUGFIX. crypto_getHASH() function. Hash was not correctly generated.
  • BUGFIX. Fixed a bug that made the recived text not be showed correctly if character encoding was not latin.
  • BUGFIX. GCM. Fixed an issue with the event of Notification received. No context was returned. This could make an application to crash if used.
  • BUGFIX. Toolbox. Fixed device_getOSversion. Returned info was wrong.

As i said, these are a lot of changes because i have been implementing all notifications related stuff and quite busy at work so i could not publish until today. I think now the libreruy is more useful. I now that i still have to improve some points but i am already in it so have patiente.

As always, I hope these changes could help you a bit more than before.

 

Do not forget to check the blog to get the Maps integration update!

More info and HowTo at https://github.com/javocsoft/javocsoft-toolbox/wiki.

github_icon

As always, library is available on GitHub

javocsoft-toolbox.

Bye.

JavocSoft 2015.

Hi all,

There are changes in JavocSoft Android Toolbox Library ready on the GitHub repository!. There is a bit more functionallity to it and, i am preparing Google Maps v2 integration to put a map in your application with a few lines of code, i hope i finish this soon.

JavocSoft Android Toolbox Library

The changes are:

  • Added method to show GPS settings panel, “dialog_showGPSDisabledAlert()”
  • Added DENSITY_XXXHIGH to device_getResolutionType() or unknown if not recognized.
  • Added the method location_addressInfo() to get some latitude and longitude address information.
  • Now the method “dialog_showExitConformationDialog()” allows to select if move the activity to the stack or close it.
  • Added a method “backPressedAction()” to enable the functionallity of “Press again back to exit”.
  • Added AnimationFactory class, under animation package, from Ephraim Tekle, to perform animations in a easy way. I use it and i think is quite useful.
  • Added an ImageDownloader class, under net/image package, to download image URLs in background and show them in its ImageView.
  • Added the possibility of custom Toast messages, “toast_createCustomToast()”, default ones are horrible XD.
  • Added the possibility of a custom Toast when user press the back button to exit if function backPressedAction() is used.
  • Added the method location_distance to know the distance in meters from one Map point to other using the Haversine algorithm.
  • The “dialog_showToastAlert()” method now allows to choose between system default toast and a custom one.
  • Now the method “share_newSharingIntent()” allows to filter applications using more than one application filter.
  • On Interstitial Ad now user clicks on it can be cached.

I hope these changes can help you a bit more.

Do not forget to check the blog to get the Maps integration update!

 

More info and HowTo at https://github.com/javocsoft/javocsoft-toolbox/wiki.

github_icon

As always, library is available on GitHub

javocsoft-toolbox.

 

Bye.

JavocSoft 2015.