Я начал изучать разработку Android-приложений, и я пытаюсь загрузить простой текстовый файл в Dropbox для начала. Всякий раз, когда у меня есть эта работа, я поднимаюсь до уровня в pdf и т. Д.Загрузка TXT в Dropbox
В любом случае я продолжаю работать, застревая при загрузке в Dropbox. Я включил библиотеки, получил активность в своем AndroidManifest и попытался как можно лучше следовать официальному руководству. Без дальнейших нонсенс, это мой код:
AndroidManifest.xml:
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboard">
<intent-filter>
<!-- Change this to be db- followed by your app key -->
<data android:scheme="db-mykeyhere" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Компоновка файл, в котором я запускать OnClick, чтобы загрузить на:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".HelloDropboxActivity" >
<Button
android:id="@+id/dropbox_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center"
android:text="@string/link_button"/>
<TextView
android:id="@+id/test_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Моя активность:
public class Settings extends Activity{
final static private String APP_KEY = "myAppKeyIsHere";
final static private String APP_SECRET = "myAppSecretIsHere";
final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;
// In the class declaration section:
private DropboxAPI<AndroidAuthSession> mDBApi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
// And later in some initialization function:
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
}
public void dropbox_button(View v){
mDBApi.getSession().startAuthentication(Settings.this);
String filePath = getApplicationContext()
.getFilesDir()
.getPath()
.toString() + "/magnus-opus.txt";
File file = new File(filePath);
try {
file.createNewFile();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream,
file.length(), null, null);
Log.i("DbExampleLog",
"The uploaded file's rev is: " + response.rev);
} catch (DropboxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void onResume() {
super.onResume();
if (mDBApi.getSession().authenticationSuccessful()) {
try {
// Required to complete auth,
// sets the access token on the session
mDBApi.getSession().finishAuthentication();
AccessTokenPair tokens = mDBApi
.getSession()
.getAccessTokenPair();
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
}
}
}
И, наконец, мой журнал ошибок:
Может ли кто-нибудь сказать мне, что здесь не так, или помочь мне? На данный момент я просто хочу загрузить файл .txt в свой Dropbox с НИЧЕГО в нем. Благодаря
~ Yenthe
Rightclick on project> свойства> вкладка пути java build> добавить внешние JAR. Вот пример: http://imgur.com/rKrhd6b – Yenthe
К сожалению, я не использую Eclipse, поэтому я не уверен в методе добавления библиотеки jar, надеюсь, кто-то другой будет, но у меня был NoClassDefFound потому что библиотека была неправильно добавлена. –
Dang haha, ну, вероятно, вы, вероятно, дали мне подсказку в правильном направлении. Надеюсь, что кто-то еще знает ответ! Спасибо за ваше время! – Yenthe