Skip to content

Commit e6e263a

Browse files
committed
Use v3.3.0
1 parent 3a5f94a commit e6e263a

File tree

7 files changed

+130
-4
lines changed

7 files changed

+130
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
==========
33

4+
Version 3.2.0 *(2017-01-04)*
5+
----------------------------
6+
* Introducing APIs for logging network requests performed by your application. Requests details along with their responses are going to be sent with each report. For more info, check: http://docs.instabug.com/docs/network-requests-logging-android
7+
* Fix bug with Screenshot gesture
8+
49
Version 3.2.0 *(2016-12-18)*
510
----------------------------
611

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Using Instabug is as easy as "Get ready, Get set, Go".
2222

2323
Grab via Gradle:
2424
```groovy
25-
compile 'com.instabug.library:instabug:3.2.0'
25+
compile 'com.instabug.library:instabug:3.3.0'
2626
```
2727
2828
or via Maven: (if you're that kind of person :bowtie:)
@@ -31,7 +31,7 @@ Using Instabug is as easy as "Get ready, Get set, Go".
3131
<dependency>
3232
<groupId>com.instabug.library</groupId>
3333
<artifactId>instabug</artifactId>
34-
<version>3.2.0</version>
34+
<version>3.3.0</version>
3535
</dependency>
3636
```
3737

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dependencies {
6060
// TODO add the following 2 lines if you exclude io.reactivex from Instabug
6161
// compile 'io.reactivex:rxjava:1.0.13'
6262
// compile 'io.reactivex:rxandroid:1.0.1'
63-
compile('com.instabug.library:instabug:3.2.0') {
63+
compile('com.instabug.library:instabug:3.3.0') {
6464
// TODO uncomment this line to exclude RxJava from Instabug and use your own version
6565
// exclude group: 'io.reactivex'
6666

app/src/main/java/com/example/instabug/ui/activities/MainActivity.java

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import android.content.Intent;
66
import android.graphics.Color;
77
import android.net.Uri;
8+
import android.os.AsyncTask;
89
import android.os.Bundle;
910
import android.support.design.widget.NavigationView;
1011
import android.support.v4.view.GravityCompat;
1112
import android.support.v4.widget.DrawerLayout;
1213
import android.support.v7.app.ActionBarDrawerToggle;
1314
import android.support.v7.widget.Toolbar;
15+
import android.util.Log;
1416
import android.view.Menu;
1517
import android.view.MenuItem;
1618
import android.view.View;
@@ -26,6 +28,18 @@
2628
import com.instabug.library.Instabug;
2729
import com.instabug.library.invocation.InstabugInvocationMode;
2830
import com.instabug.library.logging.InstabugLog;
31+
import com.instabug.library.logging.InstabugNetworkLog;
32+
33+
import org.json.JSONException;
34+
import org.json.JSONObject;
35+
36+
import java.io.BufferedReader;
37+
import java.io.IOException;
38+
import java.io.InputStream;
39+
import java.io.InputStreamReader;
40+
import java.io.OutputStreamWriter;
41+
import java.net.HttpURLConnection;
42+
import java.net.URL;
2943

3044
import butterknife.Bind;
3145
import butterknife.ButterKnife;
@@ -138,6 +152,11 @@ public void onNewMessageCountClicked() {
138152
.show();
139153
}
140154

155+
@OnClick(R.id.do_network_request)
156+
public void onDoNetworkRequestClicked(){
157+
new FetchMoviesData().execute();
158+
}
159+
141160
public void onHeaderImageClicked() {
142161
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.instabug.com"));
143162
startActivity(browserIntent);
@@ -200,4 +219,99 @@ public Intent getShareIntent() {
200219
shareIntent.putExtra(Intent.EXTRA_TEXT, sharedText);
201220
return shareIntent;
202221
}
222+
223+
private class FetchMoviesData extends AsyncTask<Void, Void, String> {
224+
225+
@Override
226+
protected String doInBackground(Void... params) {
227+
// These two need to be declared outside the try/catch
228+
// so that they can be closed in the finally block.
229+
HttpURLConnection urlConnection = null;
230+
BufferedReader reader = null;
231+
232+
// Will contain the raw JSON response as a string.
233+
String moviesJsonStr = null;
234+
235+
try {
236+
237+
URL url = new URL("http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=a491e06af68296a1fad86c70235e98f9 ");
238+
// Create the request to OpenWeatherMap, and open the connection
239+
urlConnection = (HttpURLConnection) url.openConnection();
240+
urlConnection.setDoOutput(true);
241+
urlConnection.setRequestMethod("POST");
242+
urlConnection.setUseCaches(false);
243+
urlConnection.setConnectTimeout(10000);
244+
urlConnection.setReadTimeout(10000);
245+
urlConnection.setRequestProperty("Content-Type", "application/json");
246+
urlConnection.connect();
247+
248+
//Create JSONObject here
249+
JSONObject jsonParam = new JSONObject();
250+
try {
251+
jsonParam.put("ID", "25");
252+
jsonParam.put("description", "Real");
253+
jsonParam.put("enable", "true");
254+
} catch (JSONException e) {
255+
e.printStackTrace();
256+
}
257+
258+
259+
OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
260+
out.write(jsonParam.toString());
261+
out.close();
262+
263+
// Read the input stream into a String
264+
InputStream inputStream = urlConnection.getInputStream();
265+
StringBuffer buffer = new StringBuffer();
266+
if (inputStream == null) {
267+
// Nothing to do.
268+
return null;
269+
270+
}
271+
reader = new BufferedReader(new InputStreamReader(inputStream));
272+
273+
String line;
274+
while ((line = reader.readLine()) != null) {
275+
// Since it's JSON, adding a newline isn't necessary (it won't affect parsing)
276+
// But it does make debugging a *lot* easier if you print out the completed
277+
// buffer for debugging.
278+
buffer.append(line + "\n");
279+
}
280+
281+
if (buffer.length() == 0) {
282+
// Stream was empty. No point in parsing.
283+
return null;
284+
}
285+
moviesJsonStr = buffer.toString();
286+
287+
//logging network request to instabug
288+
InstabugNetworkLog networkLog = new InstabugNetworkLog();
289+
networkLog.Log(urlConnection, jsonParam.toString(), moviesJsonStr);
290+
291+
return moviesJsonStr;
292+
} catch (IOException e) {
293+
Log.e("MainActivity", "Error ", e);
294+
// If the code didn't successfully get the weather data, there's no point in attemping
295+
// to parse it.
296+
return null;
297+
} finally {
298+
if (urlConnection != null) {
299+
urlConnection.disconnect();
300+
}
301+
if (reader != null) {
302+
try {
303+
reader.close();
304+
} catch (final IOException e) {
305+
Log.e("MainActivity", "Error closing stream", e);
306+
}
307+
}
308+
}
309+
}
310+
311+
@Override
312+
protected void onPostExecute(String s) {
313+
super.onPostExecute(s);
314+
Log.d("Response", s + "");
315+
}
316+
}
203317
}

app/src/main/res/layout/content_main.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
android:padding="10dp"
6363
android:text="@string/action_show_new_messages_count" />
6464

65+
<Button
66+
android:id="@+id/do_network_request"
67+
android:layout_width="match_parent"
68+
android:layout_height="wrap_content"
69+
android:padding="10dp"
70+
android:text="@string/action_do_network_request" />
6571

6672
<LinearLayout
6773
android:layout_width="match_parent"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@
2626
<string name="action_show_new_messages_count">Show new messages count</string>
2727
<string name="action_primary_color">Choose primary color</string>
2828
<string name="action_show_intro_message">Show intro message</string>
29+
<string name="action_do_network_request">Do network request</string>
2930
</resources>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.2'
8+
classpath 'com.android.tools.build:gradle:2.2.3'
99
}
1010
}
1111

0 commit comments

Comments
 (0)