2
iphone/ipad 앱을 개발할 때 iOS 용 스크린 샷 플러그인을 사용했습니다. 지금은 앱의 안드로이드 버전을 만들고 있으며 플러그인의 안드로이드 버전을 구현하려고합니다.JSON 전화 걸기 플러그인을 호출 할 때 오류가 발생합니다.
는플러그인 FO 내 자바 부분은 다음과 같습니다
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 {
private PluginResult result = null;
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
// starting on ICS, some WebView methods
// can only be called on UI threads
super.cordova.getActivity().runOnUiThread(new Runnable() {
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);
result = new PluginResult(PluginResult.Status.OK);
} catch (IOException e) {
result = new PluginResult(PluginResult.Status.IO_EXCEPTION, e.getMessage());
}
}
});
// waiting ui thread to finish
while (this.result == null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignoring exception, since we have to wait
// ui thread to finish
}
}
return this.result;
}
}
내 Screenshot.js은 다음과 같습니다
(function() {
/* Get local ref to global PhoneGap/Cordova/cordova object for exec function.
- This increases the compatibility of the plugin. */
var cordovaRef = window.PhoneGap || window.Cordova || window.cordova; // old to new fallbacks
/**
* This class exposes the ability to take a Screenshot to JavaScript
*/
function Screenshot() { }
/**
* Save the screenshot to the user's Photo Library
*/
Screenshot.prototype.saveScreenshot = function() {
cordovaRef.exec(null, null, "Screenshot", "saveScreenshot", []);
};
if (!window.plugins) {
window.plugins = {};
}
if (!window.plugins.screenshot) {
window.plugins.screenshot = new Screenshot();
}
})(); /* End of Temporary Scope. */
지금이 코드를 사용하여 내 screenshot.js 함수를 호출하려고 :
function takeScreenShot() {
cordovaRef.exec("Screenshot.saveScreenshot");
}
그러나 내가 할 모든 난에서 JSON으로 변환하라는 곳 메신저를 알고, JSON 오류입니다 자바 문자열하지만 난 단지 그것을 변경하는 방법을 알아낼 수 없습니다. 임 잘못하시기 바랍니다가는 곳
ERROR: org.json.JSONException: Value undefined of type java.lang.String cannot be converted to JSONArray.
Error: Status=8 Message=JSON error
file:///android_asset/www/cordova-2.0.0.js: Line 938 : Error: Status=8 Message=JSON error
Error: Status=8 Message=JSON error at file:///android_asset_/www/cordova-2.0.0.js:938
사람이 나를 인도 할 수 : 좋아 그럼 난
내 오류
는 다음과 같이 ... 그 잘못이 무엇인지 생각? 해결
[PhoneGap Screenshot plugin in Cordova 2.0.0] 가능한 복제본 (http://stackoverflow.com/questions/12424865/phonegap-screenshot-plugin-in-cordova-2-0-0) –