mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Merge branch 'master' into plugin_reset
This commit is contained in:
commit
486eb149f2
@ -187,7 +187,7 @@ public class FileTransfer extends Plugin {
|
|||||||
FileProgressResult progress = new FileProgressResult();
|
FileProgressResult progress = new FileProgressResult();
|
||||||
|
|
||||||
// Get a input stream of the file on the phone
|
// Get a input stream of the file on the phone
|
||||||
FileInputStream fileInputStream = (FileInputStream) getPathFromUri(source);
|
InputStream inputStream = getPathFromUri(source);
|
||||||
|
|
||||||
DataOutputStream dos = null;
|
DataOutputStream dos = null;
|
||||||
|
|
||||||
@ -295,12 +295,18 @@ public class FileTransfer extends Plugin {
|
|||||||
|
|
||||||
int stringLength = extraBytes.length + midParams.length() + tailParams.length() + fileNameBytes.length;
|
int stringLength = extraBytes.length + midParams.length() + tailParams.length() + fileNameBytes.length;
|
||||||
Log.d(LOG_TAG, "String Length: " + stringLength);
|
Log.d(LOG_TAG, "String Length: " + stringLength);
|
||||||
int fixedLength = (int) fileInputStream.getChannel().size() + stringLength;
|
int fixedLength = -1;
|
||||||
|
if (inputStream instanceof FileInputStream) {
|
||||||
|
fixedLength = (int) ((FileInputStream)inputStream).getChannel().size() + stringLength;
|
||||||
|
progress.setLengthComputable(true);
|
||||||
|
progress.setTotal(fixedLength);
|
||||||
|
}
|
||||||
Log.d(LOG_TAG, "Content Length: " + fixedLength);
|
Log.d(LOG_TAG, "Content Length: " + fixedLength);
|
||||||
// setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
|
// setFixedLengthStreamingMode causes and OutOfMemoryException on pre-Froyo devices.
|
||||||
// http://code.google.com/p/android/issues/detail?id=3164
|
// http://code.google.com/p/android/issues/detail?id=3164
|
||||||
// It also causes OOM if HTTPS is used, even on newer devices.
|
// It also causes OOM if HTTPS is used, even on newer devices.
|
||||||
chunkedMode = chunkedMode && (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO || useHttps);
|
chunkedMode = chunkedMode && (Build.VERSION.SDK_INT < Build.VERSION_CODES.FROYO || useHttps);
|
||||||
|
chunkedMode = chunkedMode || (fixedLength == -1);
|
||||||
|
|
||||||
if (chunkedMode) {
|
if (chunkedMode) {
|
||||||
conn.setChunkedStreamingMode(maxBufferSize);
|
conn.setChunkedStreamingMode(maxBufferSize);
|
||||||
@ -318,12 +324,12 @@ public class FileTransfer extends Plugin {
|
|||||||
dos.writeBytes(midParams);
|
dos.writeBytes(midParams);
|
||||||
|
|
||||||
// create a buffer of maximum size
|
// create a buffer of maximum size
|
||||||
bytesAvailable = fileInputStream.available();
|
bytesAvailable = inputStream.available();
|
||||||
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||||
buffer = new byte[bufferSize];
|
buffer = new byte[bufferSize];
|
||||||
|
|
||||||
// read file and write it into form...
|
// read file and write it into form...
|
||||||
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
bytesRead = inputStream.read(buffer, 0, bufferSize);
|
||||||
totalBytes = 0;
|
totalBytes = 0;
|
||||||
|
|
||||||
long prevBytesRead = 0;
|
long prevBytesRead = 0;
|
||||||
@ -335,9 +341,9 @@ public class FileTransfer extends Plugin {
|
|||||||
prevBytesRead = totalBytes;
|
prevBytesRead = totalBytes;
|
||||||
Log.d(LOG_TAG, "Uploaded " + totalBytes + " of " + fixedLength + " bytes");
|
Log.d(LOG_TAG, "Uploaded " + totalBytes + " of " + fixedLength + " bytes");
|
||||||
}
|
}
|
||||||
bytesAvailable = fileInputStream.available();
|
bytesAvailable = inputStream.available();
|
||||||
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
bufferSize = Math.min(bytesAvailable, maxBufferSize);
|
||||||
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
|
bytesRead = inputStream.read(buffer, 0, bufferSize);
|
||||||
if (objectId != null) {
|
if (objectId != null) {
|
||||||
// Only send progress callbacks if the JS code sent us an object ID,
|
// Only send progress callbacks if the JS code sent us an object ID,
|
||||||
// so we don't spam old versions with unrecognized callbacks.
|
// so we don't spam old versions with unrecognized callbacks.
|
||||||
@ -358,7 +364,7 @@ public class FileTransfer extends Plugin {
|
|||||||
dos.writeBytes(tailParams);
|
dos.writeBytes(tailParams);
|
||||||
|
|
||||||
// close streams
|
// close streams
|
||||||
fileInputStream.close();
|
inputStream.close();
|
||||||
dos.flush();
|
dos.flush();
|
||||||
dos.close();
|
dos.close();
|
||||||
|
|
||||||
|
@ -100,7 +100,9 @@ public class NetworkManager extends Plugin {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
|
// (The null check is for the ARM Emulator, please use Intel Emulator for better results)
|
||||||
|
if(webView != null)
|
||||||
|
updateConnectionInfo((NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
cordova.getActivity().registerReceiver(this.receiver, intentFilter);
|
cordova.getActivity().registerReceiver(this.receiver, intentFilter);
|
||||||
@ -208,10 +210,9 @@ public class NetworkManager extends Plugin {
|
|||||||
result.setKeepCallback(true);
|
result.setKeepCallback(true);
|
||||||
this.success(result, this.connectionCallbackId);
|
this.success(result, this.connectionCallbackId);
|
||||||
|
|
||||||
// Send to all plugins
|
|
||||||
webView.postMessage("networkconnection", type);
|
webView.postMessage("networkconnection", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the type of connection
|
* Determine the type of connection
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user