質問編集履歴
3
返信内容に対してのソースコードの記述
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,7 +30,8 @@
|
|
30
30
|
を利用すれば、アプリ上からテキストファイルの内容を指定し、保存することができる。というのはわかったのですが、どの文章でテキストフォルダ内の内容を決めているのかがわかりません。
|
31
31
|
|
32
32
|
SaverMain.javaソースコード
|
33
|
-
|
33
|
+
```java
|
34
|
+
コード
|
34
35
|
|
35
36
|
// ------------------------------------------------------------------------------
|
36
37
|
// Copyright (c) 2014 Microsoft Corporation
|
@@ -183,4 +184,20 @@
|
|
183
184
|
}
|
184
185
|
}
|
185
186
|
|
187
|
+
|
188
|
+
```
|
186
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////```
|
190
|
+
2016/11/22追記2
|
191
|
+
Y.H.さんへの返信
|
192
|
+
|
193
|
+
このサンプルプログラムを実行した場合、'a'から'z'まで指定キロバイトまで延々と出力されたテキストファイルができるわけなのですが、例えばテキストファイルの中身を1とだけ入れたい場合は、
|
194
|
+
|
195
|
+
```java
|
196
|
+
コード
|
197
|
+
byte[] buffer = new byte[bufferSize];
|
198
|
+
for (int i = 0; i < buffer.length; i++) {
|
199
|
+
buffer[i] = (byte)('a' + i % alphabetRange);
|
200
|
+
}
|
201
|
+
```
|
202
|
+
のbuffer[i] = (byte)(このぶぶんを変更);
|
203
|
+
すればよいのでしょうか?
|
2
誤字修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
を利用すれば、アプリ上からテキストファイルの内容を指定し、保存することができる。というのはわかったのですが、どの文章でテキストフォルダ内の内容を決めているのかがわかりません。
|
31
31
|
|
32
32
|
SaverMain.javaソースコード
|
33
|
-
///////////////////////////////////////////////////////
|
33
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
34
34
|
|
35
35
|
// ------------------------------------------------------------------------------
|
36
36
|
// Copyright (c) 2014 Microsoft Corporation
|
@@ -182,4 +182,5 @@
|
|
182
182
|
return file;
|
183
183
|
}
|
184
184
|
}
|
185
|
+
|
185
|
-
///////////////////////////////////////////////////////
|
186
|
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
1
質問の具体的な内容の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,4 +15,171 @@
|
|
15
15
|
|
16
16
|
/////////////////////////////////////////////////////////////
|
17
17
|
|
18
|
-
といったようなアプリを作成したいです。
|
18
|
+
といったようなアプリを作成したいです。
|
19
|
+
|
20
|
+
/////////////////////////////////////////////////////////////
|
21
|
+
|
22
|
+
2016/11/22追記
|
23
|
+
|
24
|
+
[Android 向けの OneDrive ピッカーおよぴセーバー](https://msdn.microsoft.com/ja-jp/library/dn833235.aspx#sectionSection1)
|
25
|
+
|
26
|
+
↑上記のサイトの
|
27
|
+
"onedrive-picker-android"
|
28
|
+
に入っている
|
29
|
+
"SaverSample"内の"SaverMain.java"
|
30
|
+
を利用すれば、アプリ上からテキストファイルの内容を指定し、保存することができる。というのはわかったのですが、どの文章でテキストフォルダ内の内容を決めているのかがわかりません。
|
31
|
+
|
32
|
+
SaverMain.javaソースコード
|
33
|
+
///////////////////////////////////////////////////////
|
34
|
+
|
35
|
+
// ------------------------------------------------------------------------------
|
36
|
+
// Copyright (c) 2014 Microsoft Corporation
|
37
|
+
//
|
38
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
39
|
+
// of this software and associated documentation files (the "Software"), to deal
|
40
|
+
// in the Software without restriction, including without limitation the rights
|
41
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
42
|
+
// copies of the Software, and to permit persons to whom the Software is
|
43
|
+
// furnished to do so, subject to the following conditions:
|
44
|
+
//
|
45
|
+
// The above copyright notice and this permission notice shall be included in
|
46
|
+
// all copies or substantial portions of the Software.
|
47
|
+
//
|
48
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
49
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
50
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
51
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
52
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
53
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
54
|
+
// THE SOFTWARE.
|
55
|
+
// ------------------------------------------------------------------------------
|
56
|
+
|
57
|
+
package com.example.onedrivesdk.saversample;
|
58
|
+
|
59
|
+
import java.io.*;
|
60
|
+
|
61
|
+
import android.app.Activity;
|
62
|
+
import android.content.Intent;
|
63
|
+
import android.net.Uri;
|
64
|
+
import android.os.*;
|
65
|
+
import android.view.View;
|
66
|
+
import android.view.View.OnClickListener;
|
67
|
+
import android.widget.*;
|
68
|
+
|
69
|
+
import com.microsoft.onedrivesdk.saver.*;
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Activity that shows how the OneDrive SDK can be used for file saving
|
73
|
+
*
|
74
|
+
* @author pnied
|
75
|
+
*/
|
76
|
+
public class SaverMain extends Activity {
|
77
|
+
|
78
|
+
/**
|
79
|
+
* The default file size
|
80
|
+
*/
|
81
|
+
private static final int DEFAULT_FILE_SIZE_KB = 100;
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Registered Application id for OneDrive {@see http://go.microsoft.com/fwlink/p/?LinkId=193157}
|
85
|
+
*/
|
86
|
+
private static final String ONEDRIVE_APP_ID = "48122D4E";
|
87
|
+
|
88
|
+
/**
|
89
|
+
* The onClickListener that will start the OneDrive Picker
|
90
|
+
*/
|
91
|
+
private final OnClickListener mStartPickingListener = new OnClickListener() {
|
92
|
+
@Override
|
93
|
+
public void onClick(final View v) {
|
94
|
+
final Activity activity = (Activity) v.getContext();
|
95
|
+
activity.findViewById(R.id.result_table).setVisibility(View.INVISIBLE);
|
96
|
+
|
97
|
+
final String filename = ((EditText)activity.findViewById(R.id.file_name_edit_text))
|
98
|
+
.getText().toString();
|
99
|
+
final String fileSizeString = ((EditText)activity.findViewById(R.id.file_size_edit_text))
|
100
|
+
.getText().toString();
|
101
|
+
int size;
|
102
|
+
try {
|
103
|
+
size = Integer.parseInt(fileSizeString);
|
104
|
+
} catch (final NumberFormatException nfe) {
|
105
|
+
size = DEFAULT_FILE_SIZE_KB;
|
106
|
+
}
|
107
|
+
|
108
|
+
// Create a file
|
109
|
+
final File f = createExternalSdCardFile(filename, size);
|
110
|
+
|
111
|
+
// Start the saver
|
112
|
+
mSaver.startSaving(activity, filename, Uri.parse("file://" + f.getAbsolutePath()));
|
113
|
+
}
|
114
|
+
};
|
115
|
+
|
116
|
+
/**
|
117
|
+
* The OneDrive saver instance used by this activity
|
118
|
+
*/
|
119
|
+
private ISaver mSaver;
|
120
|
+
|
121
|
+
@Override
|
122
|
+
protected void onCreate(final Bundle savedInstanceState) {
|
123
|
+
super.onCreate(savedInstanceState);
|
124
|
+
setContentView(R.layout.activity_saver_main);
|
125
|
+
|
126
|
+
// Create the picker instance
|
127
|
+
mSaver = Saver.createSaver(ONEDRIVE_APP_ID);
|
128
|
+
|
129
|
+
// Add the start saving listener
|
130
|
+
findViewById(R.id.startSaverButton).setOnClickListener(mStartPickingListener);
|
131
|
+
}
|
132
|
+
|
133
|
+
@Override
|
134
|
+
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
135
|
+
// Check that we were able to save the file on OneDrive
|
136
|
+
final TextView overallResult = (TextView) findViewById(R.id.overall_result);
|
137
|
+
final TextView errorResult = (TextView) findViewById(R.id.error_type_result);
|
138
|
+
final TextView debugErrorResult = (TextView) findViewById(R.id.debug_error_result);
|
139
|
+
|
140
|
+
try {
|
141
|
+
mSaver.handleSave(requestCode, resultCode, data);
|
142
|
+
overallResult.setText(getString(R.string.overall_result_success));
|
143
|
+
errorResult.setText(getString(R.string.error_message_none));
|
144
|
+
debugErrorResult.setText(getString(R.string.error_message_none));
|
145
|
+
} catch (final SaverException e) {
|
146
|
+
overallResult.setText(getString(R.string.overall_result_failure));
|
147
|
+
errorResult.setText(e.getErrorType().toString());
|
148
|
+
debugErrorResult.setText(e.getDebugErrorInfo());
|
149
|
+
}
|
150
|
+
findViewById(R.id.result_table).setVisibility(View.VISIBLE);
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Creates an file on the SDCard
|
155
|
+
* @param filename The name of the file to create
|
156
|
+
* @param size The size in KB to make the file
|
157
|
+
* @return The {@link File} object that was created
|
158
|
+
*/
|
159
|
+
private File createExternalSdCardFile(final String filename, final int size) {
|
160
|
+
final int bufferSize = 1024;
|
161
|
+
final int alphabetRange = 'z' - 'a';
|
162
|
+
File file = null;
|
163
|
+
try {
|
164
|
+
file = new File(Environment.getExternalStorageDirectory(), filename);
|
165
|
+
final FileOutputStream fos = new FileOutputStream(file);
|
166
|
+
|
167
|
+
// Create a 1 kb size buffer to use in writing the temp file
|
168
|
+
byte[] buffer = new byte[bufferSize];
|
169
|
+
for (int i = 0; i < buffer.length; i++) {
|
170
|
+
buffer[i] = (byte)('a' + i % alphabetRange);
|
171
|
+
}
|
172
|
+
|
173
|
+
// Write out the file, 1 kb at a time
|
174
|
+
for (int i = 0; i < size; i++) {
|
175
|
+
fos.write(buffer, 0, buffer.length);
|
176
|
+
}
|
177
|
+
|
178
|
+
fos.close();
|
179
|
+
} catch (final IOException e) {
|
180
|
+
Toast.makeText(this, "Error when creating the file: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
181
|
+
}
|
182
|
+
return file;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
///////////////////////////////////////////////////////
|