Skip to content

Commit 3d82eb4

Browse files
authored
Merge pull request #365 from Microsoft/distribute
Merge distribute to develop
2 parents ba32f56 + 4dabcb7 commit 3d82eb4

File tree

112 files changed

+10396
-1135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+10396
-1135
lines changed

README.md

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ The SDK is currently in private beta release and we support the following servic
1616

1717
2. **Crashes**: The Mobile Center SDK will automatically generate a crash log every time your app crashes. The log is first written to the device's storage and when the user starts the app again, the crash report will be forwarded to Mobile Center. Collecting crashes works for both beta and live apps, i.e. those submitted to Google Play or other app stores. Crash logs contain viable information for you to help resolve the issue. The SDK gives you a lot of flexibility how to handle a crash log. As a developer you can collect and add additional information to the report if you like.
1818

19+
3. **Distribute**: Our SDK will let your users install a new version of the app when you distribute it via Mobile Center. With a new version of the app available, the SDK will present an update dialog to the users to either download or ignore the latest version. Once they click "Download", SDK will start the installation process of your application. Note that this feature will `NOT` work if your app is deployed to the app store, if you are developing locally or if the app is a debug build.
20+
1921
This document contains the following sections:
2022

2123
1. [Prerequisites](#1-prerequisites)
2224
2. [Add Mobile Center SDK modules](#2-add-mobile-center-sdk-modules)
2325
3. [Start the SDK](#3-start-the-sdk)
2426
4. [Analytics APIs](#4-analytics-apis)
2527
5. [Crashes APIs](#5-crashes-apis)
26-
6. [Advanced APIs](#6-advanced-apis)
27-
7. [Troubleshooting](#7-troubleshooting)
28-
8. [Contributing](#8-contributing)
29-
9. [Contact](#9-contact)
28+
6. [Distribute APIs](#6-distribute-apis)
29+
7. [Advanced APIs](#7-advanced-apis)
30+
8. [Troubleshooting](#8-troubleshooting)
31+
9. [Contributing](#9-contributing)
32+
10. [Contact](#10-contact)
3033

3134
Let's get started with setting up Mobile Center Android SDK in your app to use these services:
3235

@@ -43,15 +46,17 @@ The Mobile Center SDK is designed with a modular approach – a developer only n
4346

4447
Below are the steps on how to integrate our compiled libraries in your application using Android Studio and Gradle.
4548

46-
1. Open your app level build.gradle file (app/build.gradle) and include the dependencies that you want in your project. Each SDK module needs to be added as a separate dependency in this section. If you would want to use both Analytics and Crashes, add the following lines:
49+
1. Open your app level build.gradle file (app/build.gradle) and include the dependencies that you want in your project. Each SDK module needs to be added as a separate dependency in this section. If you want to include all the services - Analytics, Crashes and Distribute, add the following lines:
4750

4851
```groovy
4952
dependencies {
5053
def mobileCenterSdkVersion = '0.5.0'
5154
compile "com.microsoft.azure.mobile:mobile-center-analytics:${mobileCenterSdkVersion}"
5255
compile "com.microsoft.azure.mobile:mobile-center-crashes:${mobileCenterSdkVersion}"
56+
compile "com.microsoft.azure.mobile:mobile-center-distribute:${mobileCenterSdkVersion}"
5357
}
5458
```
59+
You can remove the dependency line for the service that you don't want to include in your app.
5560
5661
2. Save your build.gradle file and make sure to trigger a Gradle sync in Android Studio.
5762
@@ -61,21 +66,27 @@ Now that you've integrated the SDK in your application, it's time to start the S
6166
6267
To start the Mobile Center SDK in your app, follow these steps:
6368
64-
1. **Start the SDK:** Mobile Center provides developers with two services to get started – Analytics and Crashes. In order to use these services, you need to opt in for the service(s) that you'd like, meaning by default no services are started and you will have to explicitly call each of them when starting the SDK. Insert the following line inside your app's main activity class' `onCreate` callback.
69+
1. **Start the SDK:** Mobile Center provides developers with these services to get started – Analytics, Crashes and Distribute. In order to use these services, you need to opt in for the service(s) that you'd like, meaning by default no services are started and you will have to explicitly call each of them when starting the SDK. Insert the following line inside your app's main activity class' `onCreate` callback.
6570
6671
```Java
67-
MobileCenter.start(getApplication(), "{Your App Secret}", Analytics.class, Crashes.class);
72+
MobileCenter.start(getApplication(), "{Your App Secret}", Analytics.class, Crashes.class, Distribute.class);
6873
```
6974
You can also copy paste the `start` method call from the Overview page on Mobile Center portal once your app is selected. It already includes the App Secret so that all the data collected by the SDK corresponds to your application. Make sure to replace {Your App Secret} text with the actual value for your application.
7075
71-
The example above shows how to use the `start()` method and include both the Analytics and Crashes services. If you wish not to use Analytics, remove the parameter from the method call above. Note that, unless you explicitly specify each service as parameters in the start method, you can't use that Mobile Center service. Also, the `start()` API can be used only once in the lifecycle of your app – all other calls will log a warning to the console and only the services included in the first call will be available.
76+
The example above shows how to use the `start()` method and include Analytics, Crashes and Distribute services. If you wish not to onboard to any of these services, say you dont want to use features provided by Distribute service, remove the parameter from the method call above. Note that, unless you explicitly specify each service as parameters in the start method, you can't use that Mobile Center service. Also, the `start()` API can be used only once in the lifecycle of your app – all other calls will log a warning to the console and only the services included in the first call will be available.
77+
78+
For example - if you just want to onboard to Analytics service, you should modify the start() API call like below:
79+
```Java
80+
MobileCenter.start(getApplication(), "{Your App Secret}", Analytics.class);
81+
```
7282
7383
Android Studio will automatically suggest the required import statements once you insert the `start()` method-call, but if you see an error that the class names are not recognized, add the following lines to the import statements in your activity class:
7484
7585
```Java
7686
import com.microsoft.azure.mobile.MobileCenter;
7787
import com.microsoft.azure.mobile.analytics.Analytics;
7888
import com.microsoft.azure.mobile.crashes.Crashes;
89+
import com.microsoft.azure.mobile.distribute.Distribute;
7990
```
8091
8192
## 4. Analytics APIs
@@ -217,7 +228,26 @@ You create your own Crashes listener and assign it like this:
217228
}
218229
```
219230
220-
## 6. Advanced APIs
231+
## 6. Distribute APIs
232+
233+
You can easily let your users get the latest version of your app by integrating `Distribute` service of Mobile Center SDK. All you need to do is pass the service name as a parameter in the `start()` API call. Once the activity is created, the SDK checks for new updates in the background. If it finds a new update, users will see a dialog with three options - `Download`,`Postpone` and `Ignore`. If the user presses `Download`, it will trigger the new version to be installed. Postpone will delay the download until the app is opened again. Ignore will not prompt the user again for that particular app version.
234+
235+
You can easily provide your own resource strings if you'd like to localize the text displayed in the update dialog. Look at the string files [here](https://github.com/Microsoft/mobile-center-sdk-android/blob/distribute/sdk/mobile-center-distribute/src/main/res/values/strings.xml). Use the same string name and specify the localized value to be reflected in the dialog in your own app resource files.
236+
237+
* **Enable or disable Distribute:** You can change the enabled state by calling the `Distribute.setEnabled()` method. If you disable it, the SDK will not prompt your users when a new version is available for install. To re-enable it, pass `true` as a parameter in the same method.
238+
239+
```Java
240+
Distribute.setEnabled(false);
241+
```
242+
243+
You can also check if the service is enabled or not using the `isEnabled()` method. Note that it will only disable SDK features for Distribute service which is in-app updates for your application and has nothing to do with disabling `Distribute` service from Mobile Center.
244+
245+
```Java
246+
Distribute.isEnabled();
247+
```
248+
249+
250+
## 7. Advanced APIs
221251
222252
* **Debugging**: You can control the amount of log messages that show up from the Mobile Center SDK in LogCat. Use the `MobileCenter.setLogLevel()` API to enable additional logging while debugging. The log levels correspond to the ones defined in `android.util.Log`. By default, it is set it to `ASSERT` for non-debuggable applications and `WARN` for debuggable applications.
223253
@@ -237,7 +267,7 @@ You create your own Crashes listener and assign it like this:
237267
MobileCenter.setEnabled(false);
238268
```
239269
240-
## 7. Troubleshooting
270+
## 8. Troubleshooting
241271
242272
* **How long to wait for Analytics data to appear on the portal?**
243273
@@ -258,22 +288,24 @@ You create your own Crashes listener and assign it like this:
258288
259289
* **What Android permissions are required for the SDK?**
260290
Depending on the services you use, the following permissions are required:
261-
- Analytics, Crashes: `INTERNET`, `ACCESS_NETWORK_STATE`
291+
- All services: `INTERNET`, `ACCESS_NETWORK_STATE`
292+
- Distribute: `REQUEST_INSTALL_PACKAGES`, `DOWNLOAD_WITHOUT_NOTIFICATION`
262293
263294
Required permissions are automatically merged into your app's manifest by the SDK.
264295
265-
266-
## 8. Contributing
296+
None of these permissions require user approval at runtime, those are all install time permissions.
297+
298+
## 9. Contributing
267299
268300
We're looking forward to your contributions via pull requests.
269301
270-
### 8.1 Code of Conduct
302+
### 9.1 Code of Conduct
271303
272304
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact opencode@microsoft.com with any additional questions or comments.
273305
274-
### 8.2 Contributor License
306+
### 9.2 Contributor License
275307
276308
You must sign a [Contributor License Agreement](https://cla.microsoft.com/) before submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to submit a request via the [form](https://cla.microsoft.com/) and then electronically sign the CLA when you receive the email containing the link to the document. You need to sign the CLA only once to cover submission to any Microsoft OSS project.
277309
278-
## 9. Contact
310+
## 10. Contact
279311
If you have further questions or are running into trouble that cannot be resolved by any of the steps here, feel free to open a Github issue here or contact us at mobilecentersdk@microsoft.com.

apps/sasquatch/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@ android {
2121
}
2222
}
2323

24+
repositories {
25+
maven {
26+
url "http://dl.bintray.com/mobile-center/mobile-center-snapshot"
27+
}
28+
}
29+
2430
dependencies {
25-
def version = "0.5.0"
31+
def version = "0.6.0-4"
2632
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
2733
projectDependencyCompile project(':sdk:mobile-center-analytics')
2834
projectDependencyCompile project(':sdk:mobile-center-crashes')
35+
projectDependencyCompile project(':sdk:mobile-center-distribute')
2936
jcenterDependencyCompile "com.microsoft.azure.mobile:mobile-center-analytics:${version}"
3037
jcenterDependencyCompile "com.microsoft.azure.mobile:mobile-center-crashes:${version}"
38+
jcenterDependencyCompile "com.microsoft.azure.mobile:mobile-center-distribute:${version}"
3139
}

apps/sasquatch/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package="com.microsoft.azure.mobile.sasquatch">
55

66
<application
7+
android:name=".SasquatchApplication"
78
android:allowBackup="true"
89
android:icon="@mipmap/ic_launcher"
910
android:label="@string/app_name"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.microsoft.azure.mobile.sasquatch;
2+
3+
import android.app.Application;
4+
import android.util.Log;
5+
6+
import com.microsoft.azure.mobile.MobileCenter;
7+
8+
public class SasquatchApplication extends Application {
9+
10+
@Override
11+
public void onCreate() {
12+
super.onCreate();
13+
MobileCenter.setLogLevel(Log.VERBOSE);
14+
}
15+
}

apps/sasquatch/src/main/java/com/microsoft/azure/mobile/sasquatch/activities/MainActivity.java

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.support.annotation.Nullable;
1010
import android.support.v7.app.AlertDialog;
1111
import android.support.v7.app.AppCompatActivity;
12+
import android.text.TextUtils;
1213
import android.util.Log;
1314
import android.view.Menu;
1415
import android.view.MenuItem;
@@ -22,16 +23,13 @@
2223
import com.microsoft.azure.mobile.crashes.AbstractCrashesListener;
2324
import com.microsoft.azure.mobile.crashes.Crashes;
2425
import com.microsoft.azure.mobile.crashes.model.ErrorReport;
26+
import com.microsoft.azure.mobile.distribute.Distribute;
2527
import com.microsoft.azure.mobile.sasquatch.R;
2628
import com.microsoft.azure.mobile.sasquatch.features.TestFeatures;
2729
import com.microsoft.azure.mobile.sasquatch.features.TestFeaturesListAdapter;
2830

29-
import java.lang.reflect.Method;
30-
31-
3231
public class MainActivity extends AppCompatActivity {
3332

34-
static final String APP_SECRET = "45d1d9f6-2492-4e68-bd44-7190351eb5f3";
3533
static final String APP_SECRET_KEY = "appSecret";
3634
static final String LOG_URL_KEY = "logUrl";
3735
private static final String LOG_TAG = "MobileCenterSasquatch";
@@ -46,26 +44,28 @@ protected void onCreate(Bundle savedInstanceState) {
4644
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().build());
4745

4846
/* Set custom log URL if one was configured in settings. */
49-
String logUrl = sSharedPreferences.getString(LOG_URL_KEY, null);
50-
if (logUrl != null) {
51-
try {
52-
53-
/* Method name changed and jCenter not yet updated so need to use reflection. */
54-
Method setLogUrl;
55-
try {
56-
setLogUrl = MobileCenter.class.getMethod("setLogUrl", String.class);
57-
} catch (NoSuchMethodException e) {
58-
setLogUrl = MobileCenter.class.getMethod("setServerUrl", String.class);
59-
}
60-
setLogUrl.invoke(null, logUrl);
61-
} catch (Exception e) {
62-
throw new RuntimeException(e);
63-
}
47+
String logUrl = sSharedPreferences.getString(LOG_URL_KEY, getString(R.string.log_url));
48+
if (!TextUtils.isEmpty(logUrl)) {
49+
MobileCenter.setLogUrl(logUrl);
6450
}
65-
MobileCenter.setLogLevel(Log.VERBOSE);
51+
52+
/* Set crash listener. */
6653
Crashes.setListener(getCrashesListener());
67-
MobileCenter.start(getApplication(), getAppSecret(), Analytics.class, Crashes.class);
6854

55+
/* Set distribute urls. */
56+
String installUrl = getString(R.string.install_url);
57+
if (!TextUtils.isEmpty(installUrl)) {
58+
Distribute.setInstallUrl(installUrl);
59+
}
60+
String apiUrl = getString(R.string.api_url);
61+
if (!TextUtils.isEmpty(apiUrl)) {
62+
Distribute.setApiUrl(apiUrl);
63+
}
64+
65+
/* Start Mobile center. */
66+
MobileCenter.start(getApplication(), sSharedPreferences.getString(APP_SECRET_KEY, getString(R.string.app_secret)), Analytics.class, Crashes.class, Distribute.class);
67+
68+
/* Print last crash. */
6969
Log.i(LOG_TAG, "Crashes.hasCrashedInLastSession=" + Crashes.hasCrashedInLastSession());
7070
Crashes.getLastSessionCrashReport(new ResultCallback<ErrorReport>() {
7171

@@ -77,6 +77,7 @@ public void onResult(@Nullable ErrorReport data) {
7777
}
7878
});
7979

80+
/* Populate UI. */
8081
((TextView) findViewById(R.id.package_name)).setText(String.format(getString(R.string.sdk_source_format), getPackageName().substring(getPackageName().lastIndexOf(".") + 1)));
8182
TestFeatures.initialize(this);
8283
ListView listView = (ListView) findViewById(R.id.list);
@@ -100,18 +101,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
100101
return true;
101102
}
102103

103-
private String getAppSecret() {
104-
String appSecret = sSharedPreferences.getString(APP_SECRET_KEY, null);
105-
if (appSecret == null) {
106-
SharedPreferences.Editor editor = sSharedPreferences.edit();
107-
editor.putString(APP_SECRET_KEY, APP_SECRET);
108-
editor.apply();
109-
appSecret = sSharedPreferences.getString(APP_SECRET_KEY, null);
110-
}
111-
Toast.makeText(this, String.format(getString(R.string.app_secret_toast), appSecret), Toast.LENGTH_SHORT).show();
112-
return appSecret;
113-
}
114-
115104
private AbstractCrashesListener getCrashesListener() {
116105
return new AbstractCrashesListener() {
117106
@Override

0 commit comments

Comments
 (0)