質問編集履歴
3
返信内容に対してのソースコードの記述
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,9 @@
|
|
62
62
|
|
63
63
|
SaverMain.javaソースコード
|
64
64
|
|
65
|
-
|
65
|
+
```java
|
66
|
+
|
67
|
+
コード
|
66
68
|
|
67
69
|
|
68
70
|
|
@@ -368,4 +370,36 @@
|
|
368
370
|
|
369
371
|
|
370
372
|
|
373
|
+
|
374
|
+
|
375
|
+
```
|
376
|
+
|
371
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
377
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////```
|
378
|
+
|
379
|
+
2016/11/22追記2
|
380
|
+
|
381
|
+
Y.H.さんへの返信
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
このサンプルプログラムを実行した場合、'a'から'z'まで指定キロバイトまで延々と出力されたテキストファイルができるわけなのですが、例えばテキストファイルの中身を1とだけ入れたい場合は、
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
```java
|
390
|
+
|
391
|
+
コード
|
392
|
+
|
393
|
+
byte[] buffer = new byte[bufferSize];
|
394
|
+
|
395
|
+
for (int i = 0; i < buffer.length; i++) {
|
396
|
+
|
397
|
+
buffer[i] = (byte)('a' + i % alphabetRange);
|
398
|
+
|
399
|
+
}
|
400
|
+
|
401
|
+
```
|
402
|
+
|
403
|
+
のbuffer[i] = (byte)(このぶぶんを変更);
|
404
|
+
|
405
|
+
すればよいのでしょうか?
|
2
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
SaverMain.javaソースコード
|
64
64
|
|
65
|
-
///////////////////////////////////////////////////////
|
65
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
66
66
|
|
67
67
|
|
68
68
|
|
@@ -366,4 +366,6 @@
|
|
366
366
|
|
367
367
|
}
|
368
368
|
|
369
|
+
|
370
|
+
|
369
|
-
///////////////////////////////////////////////////////
|
371
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
1
質問の具体的な内容の変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,337 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
といったようなアプリを作成したいです。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
/////////////////////////////////////////////////////////////
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
2016/11/22追記
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
[Android 向けの OneDrive ピッカーおよぴセーバー](https://msdn.microsoft.com/ja-jp/library/dn833235.aspx#sectionSection1)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
↑上記のサイトの
|
52
|
+
|
53
|
+
"onedrive-picker-android"
|
54
|
+
|
55
|
+
に入っている
|
56
|
+
|
57
|
+
"SaverSample"内の"SaverMain.java"
|
58
|
+
|
59
|
+
を利用すれば、アプリ上からテキストファイルの内容を指定し、保存することができる。というのはわかったのですが、どの文章でテキストフォルダ内の内容を決めているのかがわかりません。
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
SaverMain.javaソースコード
|
64
|
+
|
65
|
+
///////////////////////////////////////////////////////
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
// ------------------------------------------------------------------------------
|
70
|
+
|
71
|
+
// Copyright (c) 2014 Microsoft Corporation
|
72
|
+
|
73
|
+
//
|
74
|
+
|
75
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
76
|
+
|
77
|
+
// of this software and associated documentation files (the "Software"), to deal
|
78
|
+
|
79
|
+
// in the Software without restriction, including without limitation the rights
|
80
|
+
|
81
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
82
|
+
|
83
|
+
// copies of the Software, and to permit persons to whom the Software is
|
84
|
+
|
85
|
+
// furnished to do so, subject to the following conditions:
|
86
|
+
|
87
|
+
//
|
88
|
+
|
89
|
+
// The above copyright notice and this permission notice shall be included in
|
90
|
+
|
91
|
+
// all copies or substantial portions of the Software.
|
92
|
+
|
93
|
+
//
|
94
|
+
|
95
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
96
|
+
|
97
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
98
|
+
|
99
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
100
|
+
|
101
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
102
|
+
|
103
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
104
|
+
|
105
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
106
|
+
|
107
|
+
// THE SOFTWARE.
|
108
|
+
|
109
|
+
// ------------------------------------------------------------------------------
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
package com.example.onedrivesdk.saversample;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
import java.io.*;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
import android.app.Activity;
|
122
|
+
|
123
|
+
import android.content.Intent;
|
124
|
+
|
125
|
+
import android.net.Uri;
|
126
|
+
|
127
|
+
import android.os.*;
|
128
|
+
|
129
|
+
import android.view.View;
|
130
|
+
|
131
|
+
import android.view.View.OnClickListener;
|
132
|
+
|
133
|
+
import android.widget.*;
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
import com.microsoft.onedrivesdk.saver.*;
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
/**
|
142
|
+
|
143
|
+
* Activity that shows how the OneDrive SDK can be used for file saving
|
144
|
+
|
145
|
+
*
|
146
|
+
|
147
|
+
* @author pnied
|
148
|
+
|
149
|
+
*/
|
150
|
+
|
151
|
+
public class SaverMain extends Activity {
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
/**
|
156
|
+
|
157
|
+
* The default file size
|
158
|
+
|
159
|
+
*/
|
160
|
+
|
161
|
+
private static final int DEFAULT_FILE_SIZE_KB = 100;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
/**
|
166
|
+
|
167
|
+
* Registered Application id for OneDrive {@see http://go.microsoft.com/fwlink/p/?LinkId=193157}
|
168
|
+
|
169
|
+
*/
|
170
|
+
|
171
|
+
private static final String ONEDRIVE_APP_ID = "48122D4E";
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
/**
|
176
|
+
|
177
|
+
* The onClickListener that will start the OneDrive Picker
|
178
|
+
|
179
|
+
*/
|
180
|
+
|
181
|
+
private final OnClickListener mStartPickingListener = new OnClickListener() {
|
182
|
+
|
183
|
+
@Override
|
184
|
+
|
185
|
+
public void onClick(final View v) {
|
186
|
+
|
187
|
+
final Activity activity = (Activity) v.getContext();
|
188
|
+
|
189
|
+
activity.findViewById(R.id.result_table).setVisibility(View.INVISIBLE);
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
final String filename = ((EditText)activity.findViewById(R.id.file_name_edit_text))
|
194
|
+
|
195
|
+
.getText().toString();
|
196
|
+
|
197
|
+
final String fileSizeString = ((EditText)activity.findViewById(R.id.file_size_edit_text))
|
198
|
+
|
199
|
+
.getText().toString();
|
200
|
+
|
201
|
+
int size;
|
202
|
+
|
203
|
+
try {
|
204
|
+
|
205
|
+
size = Integer.parseInt(fileSizeString);
|
206
|
+
|
207
|
+
} catch (final NumberFormatException nfe) {
|
208
|
+
|
209
|
+
size = DEFAULT_FILE_SIZE_KB;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
// Create a file
|
216
|
+
|
217
|
+
final File f = createExternalSdCardFile(filename, size);
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
// Start the saver
|
222
|
+
|
223
|
+
mSaver.startSaving(activity, filename, Uri.parse("file://" + f.getAbsolutePath()));
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
};
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
/**
|
232
|
+
|
233
|
+
* The OneDrive saver instance used by this activity
|
234
|
+
|
235
|
+
*/
|
236
|
+
|
237
|
+
private ISaver mSaver;
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
@Override
|
242
|
+
|
243
|
+
protected void onCreate(final Bundle savedInstanceState) {
|
244
|
+
|
245
|
+
super.onCreate(savedInstanceState);
|
246
|
+
|
247
|
+
setContentView(R.layout.activity_saver_main);
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
// Create the picker instance
|
252
|
+
|
253
|
+
mSaver = Saver.createSaver(ONEDRIVE_APP_ID);
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
// Add the start saving listener
|
258
|
+
|
259
|
+
findViewById(R.id.startSaverButton).setOnClickListener(mStartPickingListener);
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
@Override
|
266
|
+
|
267
|
+
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
268
|
+
|
269
|
+
// Check that we were able to save the file on OneDrive
|
270
|
+
|
271
|
+
final TextView overallResult = (TextView) findViewById(R.id.overall_result);
|
272
|
+
|
273
|
+
final TextView errorResult = (TextView) findViewById(R.id.error_type_result);
|
274
|
+
|
275
|
+
final TextView debugErrorResult = (TextView) findViewById(R.id.debug_error_result);
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
try {
|
280
|
+
|
281
|
+
mSaver.handleSave(requestCode, resultCode, data);
|
282
|
+
|
283
|
+
overallResult.setText(getString(R.string.overall_result_success));
|
284
|
+
|
285
|
+
errorResult.setText(getString(R.string.error_message_none));
|
286
|
+
|
287
|
+
debugErrorResult.setText(getString(R.string.error_message_none));
|
288
|
+
|
289
|
+
} catch (final SaverException e) {
|
290
|
+
|
291
|
+
overallResult.setText(getString(R.string.overall_result_failure));
|
292
|
+
|
293
|
+
errorResult.setText(e.getErrorType().toString());
|
294
|
+
|
295
|
+
debugErrorResult.setText(e.getDebugErrorInfo());
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
findViewById(R.id.result_table).setVisibility(View.VISIBLE);
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
/**
|
306
|
+
|
307
|
+
* Creates an file on the SDCard
|
308
|
+
|
309
|
+
* @param filename The name of the file to create
|
310
|
+
|
311
|
+
* @param size The size in KB to make the file
|
312
|
+
|
313
|
+
* @return The {@link File} object that was created
|
314
|
+
|
315
|
+
*/
|
316
|
+
|
317
|
+
private File createExternalSdCardFile(final String filename, final int size) {
|
318
|
+
|
319
|
+
final int bufferSize = 1024;
|
320
|
+
|
321
|
+
final int alphabetRange = 'z' - 'a';
|
322
|
+
|
323
|
+
File file = null;
|
324
|
+
|
325
|
+
try {
|
326
|
+
|
327
|
+
file = new File(Environment.getExternalStorageDirectory(), filename);
|
328
|
+
|
329
|
+
final FileOutputStream fos = new FileOutputStream(file);
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
// Create a 1 kb size buffer to use in writing the temp file
|
334
|
+
|
335
|
+
byte[] buffer = new byte[bufferSize];
|
336
|
+
|
337
|
+
for (int i = 0; i < buffer.length; i++) {
|
338
|
+
|
339
|
+
buffer[i] = (byte)('a' + i % alphabetRange);
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
// Write out the file, 1 kb at a time
|
346
|
+
|
347
|
+
for (int i = 0; i < size; i++) {
|
348
|
+
|
349
|
+
fos.write(buffer, 0, buffer.length);
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
fos.close();
|
356
|
+
|
357
|
+
} catch (final IOException e) {
|
358
|
+
|
359
|
+
Toast.makeText(this, "Error when creating the file: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
return file;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
///////////////////////////////////////////////////////
|