GithubHelp home page GithubHelp logo

johnjohndoe / android-developers-samples Goto Github PK

View Code? Open in Web Editor NEW
68.0 68.0 52.0 9.05 MB

Tracking changes for Android Developers Samples

Home Page: https://developer.android.com/samples/index.html

Java 100.00%

android-developers-samples's People

Contributors

johnjohndoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-developers-samples's Issues

Print Manager in Android

In my android application, I have an option to print the invoices for the delivery order. I am generating the Invoice content as html and sending it to android print manager as a string to print it. It is getting opened in print dialog and I am able to select a printer for printing. But after the print, my application is getting closed. But I want to redirect to the same page after the print.

Also I want to set the number of copies to 2 while printing programmatically from the android print manager. This is my source code.

private void print() {
// Create a WebView and hold on to it as the printing will start when
// load completes and we do not want the WbeView to be garbage collected.
mWebView = new WebView(this);

    // Important: Only after the page is loaded we will do the print.
    mWebView.setWebViewClient(new WebViewClient() {
        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
        @Override
        public void onPageFinished(WebView view, String url) {
            doPrint();
        }
    });


    mWebView.loadDataWithBaseURL(null, htmlDocument, "text/HTML", "UTF-8", null);

    // Load an HTML page.
    //  mWebView.loadUrl("file:///android_res/raw/motogp_stats.html");
}

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void doPrint() {


    // Get the print manager.
    PrintManager printManager = (PrintManager) getSystemService(
            Context.PRINT_SERVICE);


   // Create a wrapper PrintDocumentAdapter to clean up when done.
    PrintDocumentAdapter adapter = new PrintDocumentAdapter() {
        private final PrintDocumentAdapter mWrappedInstance =
                mWebView.createPrintDocumentAdapter();

        @Override
        public void onStart() {
            mWrappedInstance.onStart();
        }

        @Override
        public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                             CancellationSignal cancellationSignal, LayoutResultCallback callback,
                             Bundle extras) {
            mWrappedInstance.onLayout(oldAttributes, newAttributes, cancellationSignal,
                    callback, extras);
        }

        @Override
        public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
            mWrappedInstance.onWrite(pages, destination, cancellationSignal, callback);
        }



        @Override
        public void onFinish() {
            mWrappedInstance.onFinish();
            // Intercept the finish call to know when printing is done
            // and destroy the WebView as it is expensive to keep around.
            mWebView.destroy();
            mWebView = null;
        }
    };


    try{
        // Pass in the ViewView's document adapter.
       printManager.print("MotoGPstats", adapter, null);
       // printManager.print("MotoGP stats", mWebView.createPrintDocumentAdapter(), null);
        Log.i("MotoGPstats",""+mWebView.createPrintDocumentAdapter());
        Log.i("printtest",""+adapter);
    }catch (NullPointerException n){
        n.getMessage();
    }

}

SyncAdapter metadata authority

Hi great code!!

I have a problem. if i have 2 build types release and debug for example, how can i change the syncadapter authority????

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.