Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit a26668d

Browse files
committed
corrected photo logic
1 parent baec77b commit a26668d

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

app/src/main/java/com/microsoft/graph/connect/Connect.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5+
import android.os.StrictMode;
56
import android.support.multidex.MultiDex;
67
import android.support.multidex.MultiDexApplication;
78

@@ -33,6 +34,8 @@ public void onCreate(){
3334
super.onCreate();
3435

3536
mLogs = new StringBuffer();
37+
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
38+
StrictMode.setThreadPolicy(policy);
3639

3740
// Logging can be turned on four different levels: error, warning, info, and verbose. By default the sdk is turning on
3841
// verbose level logging. Any apps can use Logger.getInstance().setLogLevel(Loglevel) to enable different level of logging.

app/src/main/java/com/microsoft/graph/connect/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ public class Constants {
1111
// The Microsoft Graph delegated permissions that you set in the application
1212
// registration portal must match these scope values.
1313
// Update this constant with the scope (permission) values for your application:
14-
public static final String[] SCOPES = {"openid", "profile","Mail.ReadWrite","mail.send","Files.ReadWrite","User.ReadBasic.All"};
14+
public static final String[] SCOPES = {"openid", "Mail.ReadWrite","mail.send","Files.ReadWrite","User.ReadBasic.All"};
1515
}

app/src/main/java/com/microsoft/graph/connect/GraphServiceClientManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import android.accounts.AuthenticatorException;
88
import android.accounts.OperationCanceledException;
9+
import android.util.Log;
910

1011
import com.microsoft.graph.authentication.IAuthenticationProvider;
1112
import com.microsoft.graph.core.DefaultClientConfig;
@@ -40,6 +41,8 @@ public void authenticateRequest(IHttpRequest request) {
4041
// This header has been added to identify this sample in the Microsoft Graph service.
4142
// If you're using this code for your project please remove the following line.
4243
request.addHeader("SampleID", "android-java-connect-sample");
44+
45+
Log.i("Connect","Request: " + request.toString());
4346
} catch (AuthenticatorException e) {
4447
e.printStackTrace();
4548
} catch (IOException e) {

app/src/main/java/com/microsoft/graph/connect/GraphServiceController.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.graphics.drawable.Drawable;
1313
import android.os.Build;
1414
import android.os.Environment;
15+
import android.os.NetworkOnMainThreadException;
1516
import android.os.StrictMode;
1617
import android.support.annotation.VisibleForTesting;
1718
import android.util.Log;
@@ -119,6 +120,10 @@ public void addPictureToDraftMessage(String messageId,
119120
fileAttachment.contentBytes = attachementBytes;
120121
//fileAttachment.contentType = "image/png";
121122
fileAttachment.name = "me.png";
123+
fileAttachment.size = attachementBytes.length;
124+
fileAttachment.isInline = false;
125+
fileAttachment.id = "blabla";
126+
Log.i("connect sample","attachement id " + fileAttachment.id);
122127
mGraphServiceClient
123128
.getMe()
124129
.getMessages(messageId)
@@ -189,21 +194,40 @@ public void success(final InputStream inputStream) {
189194
try {
190195
byte[] pictureBytes = new byte[1024];
191196
BufferedInputStream bufferedInputStream = (BufferedInputStream) inputStream;
197+
byte[] buff = new byte[8000];
198+
199+
200+
ByteArrayOutputStream bao = new ByteArrayOutputStream();
201+
int bytesRead = 0;
202+
byte[] data = new byte[0];
203+
try {
204+
//This seems to be executing on the main thread!!!
205+
while ((bytesRead = bufferedInputStream.read(buff)) != -1) {
206+
bao.write(buff, 0, bytesRead);
207+
}
208+
data = bao.toByteArray();
209+
210+
} catch (NetworkOnMainThreadException ex) {
211+
Log.e("Connect" , "Attempting to read buffered network resource on main thread " + ex.getMessage());
212+
213+
}
214+
215+
192216

193-
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
194-
StrictMode.setThreadPolicy(policy);
195217

196218
//If the user's photo is not available, get the default test.jpg from the device external
197219
//storage root folder
198-
if (bufferedInputStream.available() < 1) {
220+
// if (bufferedInputStream.available() < 1) {
221+
if (data.length == 0)
222+
{
199223
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
200224
pictureBytes = getDefaultPicture();
201225
}
202226
else {
203227
pictureBytes = getTestPicture();
204228
}
205229
} else {
206-
pictureBytes = convertBufferToBytes(bufferedInputStream, inputStream.available());
230+
pictureBytes = data; //convertBufferToBytes(bufferedInputStream, inputStream.available());
207231
}
208232
callback.success(pictureBytes);
209233
} catch (IOException e) {

app/src/main/java/com/microsoft/graph/connect/SendMailActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ private void getDraftMessage(final Message aMessage, final Permission permission
223223
mGraphServiceController.getDraftMessage(aMessage.id, new ICallback<Message>() {
224224
public void success(final Message aMessage) {
225225
Log.i("SendMailActivity", "Adding picture to draft message ");
226-
addPictureToDraftMessage(aMessage, permission, bytes);
226+
sendDraftMessage(aMessage);
227+
227228
}
228229

229230
public void failure(ClientException ex) {

0 commit comments

Comments
 (0)