Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:49:20+00:00 2026-06-11T10:49:20+00:00

Ok I am trying to implement an phone gap plugin, that consists of two

  • 0

Ok I am trying to implement an phone gap plugin, that consists of two parts. I am using cordova 2.0.0 and eclipse.

Here is the java part:

package org.apache.cordova;



 import java.io.File;
    import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;

import android.graphics.Bitmap;
import android.os.Environment;
import android.view.View;

public class Screenshot extends Plugin {

    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {
        // starting on ICS, some WebView methods
        // can only be called on UI threads
        final Plugin that = this;
        final String id = callbackId;
        super.cordova.getActivity().runOnUiThread(new Runnable() {
            //@Override
            public void run() {
                View view = webView.getRootView();

                view.setDrawingCacheEnabled(true);
                Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
                view.setDrawingCacheEnabled(false);

                try {
                    File folder = new File(Environment.getExternalStorageDirectory(), "Pictures");
                    if (!folder.exists()) {
                        folder.mkdirs();
                    }

                    File f = new File(folder, "screenshot_" + System.currentTimeMillis() + ".png");

                    FileOutputStream fos = new FileOutputStream(f);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
                    that.success(new PluginResult(PluginResult.Status.OK), id);

                } catch (IOException e) {
                    that.success(new PluginResult(PluginResult.Status.IO_EXCEPTION, e.getMessage()), id);
                }
            }
        });

        PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
        result.setKeepCallback(true);
        return result;
    }

}

Here is the javascript part:

cordova.define("cordova/plugin/screenshot", function(require, exports, module) {
    var exec = require('cordova/exec');

    /**
     * This class exposes the ability to take a Screenshot to JavaScript
     */
    var Screenshot = function() {};

    /**
     * Save the screenshot to the user's Photo Library
     */
    Screenshot.prototype.saveScreenshot = function() {
        exec(null, null, "Screenshot", "saveScreenshot", []);
    };

    var screenshot = new Screenshot();
    module.exports = screenshot;

});

if (!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.screenshot) {
    window.plugins.screenshot = cordova.require("cordova/plugin/screenshot");
}

I am trying to call this with another javascript function on another page, but without success. I hide the anchors of an image on a canvas, then this line:

setTimeout(takeScreenShot,500);

EDIT — made after Simon MacDonald’s answer
this then relates to a javascript function:

function takeScreenShot() {
window.plugins.screenshot.saveScreenshot();
}

The following java prints:

System.out.println(folder);
System.out.println("screenshot_" + System.currentTimeMillis() + ".png");

Produce the following results:

/mdt/sdcard/Pictures
screenshot_1347893081276.png

EDIT After turning the device off and on again, the screenshots I took appeared, the phone seems to cache them, and not actually store them to the selected folder.

I have ensured that my config.xml and my android manifest have the right permissions and lines of code. Anyone see where im going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:49:21+00:00Added an answer on June 11, 2026 at 10:49 am

    nowhere in your code do you ever call the saveScreenshot method. Your takeScreenShot method should look like this:

    function takeScreenShot() {
        window.plugins.screenshot.saveScreenshot();
    }
    

    Then the screen shot should be saved in “/sdcard/Pictures”. This will work if:

    1. You remembered to put a plugin line into your config.xml for the screen shot plugin
    2. You mentioned this is on another page so make sure that page has a script tag for screenshot.js.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement form validation using cakephp models. Here are my code
I'm trying to implement binding validation using Silverlight on Windows Phone, but all I
Trying to implement a search similar to here .This searches properties based on city,locality,property
I am trying to implement jsr-179 APi into Nokia Symbian phone for periodic location
I'm trying to implement a Cometd/Bayeux server on Android using iJetty. The Jetty implementation
I am trying to implement user registration on my mvc3 site using fb. My
i'm having issues trying to implement a forloop in a view using a ViewModel.
I am trying to validate a phone number which is contained over two fields.
I am trying to implement application that is supported to android,iphone,blackberry,windows mobile,symbian, webos (palm).
I'm trying to implement a Drag and Drop interface for my windows phone application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.