Code Monkey home page Code Monkey logo

extractionlib's Introduction

ExtractionLib API

Sometimes we need a lot of files to be downloaded from a server,we can download all of them in the form of jar and then extract your jar file which may carry images, excel files, etc, you don't have need to worry anymore, a lot of code is already there in library.
Just you have to configure a little code in your android activity.

+First add ExtractionLib in your app level build file as follows 
  dependencies {
	        compile 'com.github.ankitdubey021:ExtractionLib:2.0'
	}


-In project level build file, add the jitpack repository

  allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Now in your activity, call the Extract class method with following prototype

public class Extract extends ActivityCompat{

public static void extract(File jarfile, String path)throws Exception{ --- }

}

  +Jar file represents the file to be extracted, and path represents where to be extracted

Sample code

void extract(){
    try {
        File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "value1.jar");
        Extract.extract(outputFile, new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "extration").toString());

        Toast.makeText(MainActivity.this, "Extracted!", Toast.LENGTH_SHORT).show();
    }catch(Exception e){
        System.out.println(e);
    }
}

Make sure, you've asked for permission at runtime to read the file as follows, otherwise you'll get exception as FileNotFoundException

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

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

}

@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) {

                    extract();
            } else {
                Toast.makeText(MainActivity.this, "Permission denied to read your External storage", Toast.LENGTH_SHORT).show();
            }
            return;
        }

    }
    
    
   
    for any query, you can mail me at -> [email protected]
}

extractionlib's People

Contributors

ankitdubey021 avatar

Watchers

Michael jentsch avatar James Cloos avatar  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.