您好我开发了支持Dropbox的应用程序。
我完成了身份验证,一切正常。
当我关闭互联网连接并尝试上传文件时,我收到成功回拨...... !!!
之后如果我打开互联网就没有任何事情发生。
这是必须发生的事情,还是某个地方我错了?
以下是我用于上传的代码
FileInputStream inputStream = null;
try {
File file = new File("/path to my file.txt");
inputStream = new FileInputStream(file);
Entry newEntry = mDBApi.putFileOverwrite("/path to my file.txt", inputStream, file.length(), null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
} catch (DropboxUnlinkedException e) {
// User has unlinked, ask them to link again here.
Log.e("DbExampleLog", "User has unlinked.");
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while uploading.");
} catch (FileNotFoundException e) {
Log.e("DbExampleLog", "File not found.");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {}
}
}
答案 0 :(得分:0)
private boolean haveNetworkConnection()
{
boolean haveConnectedWifi = false;
boolean haveConnectedMobile = false;
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] netInfo = cm.getAllNetworkInfo();
for (NetworkInfo ni : netInfo)
{
if (ni.getTypeName().equalsIgnoreCase("WIFI"))
if (ni.isConnected())
haveConnectedWifi = true;
if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
if (ni.isConnected())
haveConnectedMobile = true;
}
return haveConnectedWifi || haveConnectedMobile;
}
使用上述方法检查是否有互联网连接。这样,如果互联网连接可用,您可以检查并显示Toast消息
如果您使用此方法,请不要忘记添加
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
到您的清单文件