Git Product home page Git Product logo

zborkala / netfimno Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 3.0 47 KB

NetFimno is helper class to easily perform all kind of http requests like sending post, get request, upload and download files showing the progress. No need of using third party libraries with unverified safety threat.

Home Page: https://fimno.com/android/netfimno

Java 100.00%
android internet-connection httpurlconnection upload postreq getrequests downloader progressbar java netfimno

netfimno's Introduction

Android NetFimno

Android NetFimno is a java class which helps android developer to perform internet communication without any external third party libraries. NetFimno uses built-in android HttpUrlConnection.class to perform every kind of network requests and supports in all android versions.

What you can do with NetFimno are the following.

  • Sending GET & POST requests.
  • Uploading files and other data (optional) with progress indicators (like progressbar).
  • Downloading files from internet with progress indicators. You can hide and show the downloading notification.

All you need is

  • Add the following permissions in your AndroidManifest.xml
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />

  • Include NetFimno.java and Body.java files in your package (com.example.yourapp)

Sending GET Request.

new NetFimno("https://example.com/something.php?id=3").get(new NetFimno.OnResult() {
                           @Override
                           public void onSuccess(String response) {
                            //Your code is here
                            // if(NetFimno.isJSON(response)) {}
                           }
                           }); 

Sending POST Request.

   Body body = new Body()
                   .put("username", username)
                   .put("pwd", password)
                   .put("email", email);
                   
   new NetFimno("https://example.com/something.php").post(body.getMap(), new NetFimno.OnResult() {
                            @Override
                            public void onSuccess(String response) {
                             //Your code is here
                            }
                            }); 

Please note Body.put(String key,String value) method has two parameters

Uploading files with other data

   Body body = new Body()
                  .put("username", "Zikkoo")
                  .put("pwd", "8styadf")
                  .put("email", "[email protected]");
                  
   //You can upload more than one file, here I am uploading two files   
   Body files = new Body()
                    .put("file1", "filePath1")
                    .put("file2", "filePath2");
   new NetFimno(context,"https://example.com/something.php").multipart(files.getMap(), body.getMap(), new NetFimno.OnResultUpload() {
                           @Override
                           public void onSuccess(String response) {   
                              //Your code comes here
                           }

                           @Override
                           public void getProgress(int progress) {
                               // Progress is always in percentage
                               // myProgressBar.setProgress(progress);
                           }
                       });

Uploading files with no other data

 Body files = new Body()
                  .put("file1", "filePath1")
                  .put("file2", "filePath2");
 new NetFimno(context,"https://example.com/something.php").multipart(files.getMap(), null, new NetFimno.OnResultUpload() {
                         @Override
                         public void onSuccess(String response) {   
                            //Your code comes here
                         }

                         @Override
                         public void getProgress(int progress) {
                             // Progress is always in percentage
                             // myProgressBar.setProgress(progress);
                         }
                     });

Downloading a file from the server

    new NetFimno(context,"https://example.com/somfile.mp3")
    .setFileName("mySong.mp3")
    .setPath("audios")
    .setOnDownload(new NetFimno.OnDownload() {
         @Override
         public void progress(int percent) {   
             // Progress is always in percentage
             // myProgressBar.setProgress(progress);            
         }

         @Override
         public void complete() {
            //Your code comes here
         }
    }).download(true);

.setFileName(), .setPath() and setDownload() are optionals. You can use it or leave it like this.

new NetFimno(context,"https://example.com/somfile.mp3").download(true);

.download(true) to make notification visible and .download(false) is to make it invisible

JSON Checker

You can also check the response whether is in JSON format or not using static NetFimno.isJSON(response) method NetFimno.isJSON(response) returns true if the response is in JSON format. Otherwise, it returns false.

netfimno's People

Contributors

zborkala avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.