因此,第一个Activity初始化dbxAccount对象。 然后将此实例传递给第二个Activity,“应该”使用它来上传数据。
每次使用dbxFileSystem时,应用程序崩溃都会显示:磁盘I / O错误
public class Upload extends Activity {
private static final String appKey = "xxx";
private static final String appSecret = "yyy";
private static final int REQUEST_LINK_TO_DBX = 0;
DbxFileSystem dbxFs;
DbxFile imageLocationDbxF;
DbxPath protocollFile;
private DbxAccountManager mDbxAcctMgr;
String dataPath;
Button retry;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload);
mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(),
appKey, appSecret);
onClickLinkToDropbox();
Button getBack = (Button) findViewById(R.id.backId);
retry = (Button) findViewById(R.id.retry);
retry.setVisibility(View.INVISIBLE);
getBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DbxAccount chosenAccount=mDbxAcctMgr.getLinkedAccount();
//-----> here the dbxAccount Object is delivered <------
MovementDetection.mAccount=chosenAccount;
Intent sendAccount = new Intent(getApplicationContext(), ManueActivity.class);
startActivity(sendAccount);
}
});
retry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClickLinkToDropbox();
}
});
}
@Override
protected void onResume() {
super.onResume();
if (mDbxAcctMgr.hasLinkedAccount()) {
// showLinkedView();
try {
dbxFs = DbxFileSystem
.forAccount(mDbxAcctMgr.getLinkedAccount());
Log.i(TAG, "Account linked!!!");
// -> check if the folder exists!
} catch (Unauthorized e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
retry.setVisibility(View.VISIBLE);
}
}
private void onClickLinkToDropbox() {
mDbxAcctMgr.startLink((Activity) this, REQUEST_LINK_TO_DBX);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LINK_TO_DBX) {
if (resultCode == Activity.RESULT_OK) {
Log.i("", "Linked---!!");
} else {
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
调用上传或创建图像/文件/文件夹的方法...在此活动中有效。但此活动仅用于验证当前使用的保管箱帐户。
第二个Activity现在有一个inizialized dbxAccount 对象。它被描述为静态变量。 (---&gt;参见此评论&lt; ---) 然后通过Intent
调用第二个Activitypublic class MovementDetection extends Activity implements
CvCameraViewListener2 {
private CameraView mOpenCvCameraView;
public static DbxAccount mAccount;
public DbxFileSystem dbxFs;
DbxFile imageLocationDbxF;
private DbxPath DestinationFolder;
private static final int REQUEST_LINK_TO_DBX = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// do some stuff here
Log.i(TAG, "the linked account is: "+mAccount.getAccountInfo());
// Log cat shows normal contents of this Object as it should
}
@Override
public void onResume() {
super.onResume();
if (mAccount.isLinked()) {
// showLinkedView();
try {
dbxFs = DbxFileSystem
.forAccount(mAccount);
Log.i(TAG, "Account linked!!!");
} catch (Unauthorized e) {
e.printStackTrace();
}
}else{
Log.i(TAG, "no linkedAccount found");
}
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this,
mLoaderCallback);
}
@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
// does some stuff here....
DbxFile testFile= dbxFs.create(new DbxPath("hello.txt"));
//here the program stops!
return inputFrame.rgba();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LINK_TO_DBX) {
if (resultCode == Activity.RESULT_OK) {
Log.i("", "Linked---!!");
} else {
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
这是我的manifest.xml
> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.opencv.Pulsdetection"
android:targetSdkVersion="18"
android:versionCode="21"
android:versionName="2.1" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<activity
android:name="org.opencv.MotionControl.Main"
android:configChanges="keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="landscape" >
</activity>
<activity
android:name="org.opencv.MotionControl.ManueActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.opencv.MotionControl.CameraChose"
android:label="@string/title_activity_camera_chose" >
</activity>
<activity
android:name="org.opencv.Camera.CameraChose"
android:label="@string/title_activity_camera_chose" >
</activity>
<activity
android:name="org.opencv.Camera.ShowAndUpload"
android:label="@string/title_activity_show_and_upload" >
</activity>
<activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask" >
<intent-filter>
<data android:scheme="xxxx" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.dropbox.sync.android.DbxSyncService"
android:enabled="true"
android:exported="false"
android:label="Dropbox Sync"/>
<activity
android:name="org.dropbox.connect.ConnectToDropbox"
android:label="@string/title_activity_connect_to_dropbox" >
</activity>
<activity
android:name="org.FileSystems.LookUpPath"
android:label="@string/title_activity_look_up_path" >
</activity>
<activity
android:name="org.dropbox.connect.ShowAndUploadImages"
android:label="@string/title_activity_show_and_upload_images" >
</activity>
<activity
android:name="org.dropbox.connect.Upload"
android:label="@string/title_activity_upload" >
</activity>
<activity
android:name="org.dropbox.connect.AccountManager"
android:label="@string/title_activity_account_manager" >
</activity>
<activity
android:name="org.opencv.MotionControl.MovementDetection"
android:configChanges="keyboardHidden|orientation"
android:label="@string/title_activity_open_viedo"
android:screenOrientation="landscape" >
</activity>
</application>
<supports-screens
android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:resizeable="true"
android:smallScreens="true" />
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front.autofocus"
android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
由于这是我的第一个问题,我很抱歉格式,我不知道如何发布错误代码..
我期待着一个anwser 谢谢!
答案 0 :(得分:0)
不要在活动
上设置静态变量// do not do this!
MovementDetection.mAccount=chosenAccount;
当用户链接到某个帐户时,它会在应用的生命周期内保持关联状态(直到卸载或明确取消关联)。
当您希望在其他活动中访问Dropbox时(链接后 - 可能是一次性设置或类似设置的一部分)
DbxAccountManager mDbxAcctMgr = DbxAccountManager.getInstance(
getApplicationContext(), DROPBOX_APPKEY,
DROPBOX_SECRETKEY);
try {
if (mDbxAcctMgr.hasLinkedAccount()
&& mDbxAcctMgr.getLinkedAccount().isLinked()) {
dbxFs = DbxFileSystem
.forAccount(mDbxAcctMgr.getLinkedAccount());
} else {
/* Might want to navigate to Dropbox signup Activity here */
}
} catch (Unauthorized e) {
Log.e(TAG, e.getMessage(), e);
} catch (InvalidPathException e) {
Log.e(TAG, e.getMessage(), e);
} catch (DbxException e) {
Log.e(TAG, e.getMessage(), e);
}
在此步骤dbxFs
初始化并准备好使用之后,否则由于异常而为空。