Skip to content

Commit

Permalink
Use 2.0.0 beta5 (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
idelgado committed Apr 13, 2017
1 parent f7c982d commit 6d51d35
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 323 deletions.
48 changes: 13 additions & 35 deletions README.md
Expand Up @@ -9,7 +9,7 @@ Get started with Voice on Android:

## Quickstart

To get started with the Quickstart application follow these steps. Steps 1-6 will allow you to make a call. The remaining steps 7-8 will enable push notifications using GCM.
To get started with the Quickstart application follow these steps. Steps 1-6 will allow you to make a call. The remaining steps 7-8 will enable push notifications using FCM.


1. [Open this project in Android Studio](#bullet1)
Expand All @@ -18,18 +18,14 @@ To get started with the Quickstart application follow these steps. Steps 1-6 wil
4. [Create a TwiML application](#bullet4)
5. [Configure your application server](#bullet5)
6. [Run the app](#bullet6)
7. [Generate google-services.json from the Google Developer Console](#bullet7)
8. [Add a Push Credential using your GCM Server API Key](#bullet8)
7. [Generate google-services.json](#bullet7)
8. [Add a Push Credential using your FCM Server API Key](#bullet8)
9. [Receiving an Incoming Notification](#bullet9)


### <a name="bullet1"></a>1. Open the project in Android Studio
<img width="700px" src="images/quickstart/import_project.png"/>

For now you will see an error in the console stating `Failed to retrieve GCM token` and this is because you don’t have a valid `google-services.json` file yet to enable push notifications. We will obtain it in step 7.

<img width="700px" src="images/quickstart/invalid_sender.png"/>

### <a name="bullet2"></a>2. Create a Voice API key

Go to the [API Keys page](https://www.twilio.com/console/voice/dev-tools/api-keys) and create a new API key.
Expand Down Expand Up @@ -92,31 +88,29 @@ Press the call button to connect to Twilio

<img height="500px" src="images/quickstart/voice_make_call.png">

### <a name="bullet7"></a>7. Generate `google-services.json` from the Google Developer Console

The Programmable Voice Android SDK uses Google Cloud Messaging push notifications to let your application know when it is receiving an incoming call. If you want your users to receive incoming calls, you’ll need to enable GCM in your application.
### <a name="bullet7"></a>7. Generate `google-services.json`

Follow the steps in the [Google Developers Console](https://developers.google.com/mobile/add). You must enter the correct Android package name, in this case `com.twilio.voice.quickstart` .
The Programmable Voice Android SDK uses Firebase Cloud Messaging push notifications to let your application know when it is receiving an incoming call. If you want your users to receive incoming calls, you’ll need to enable FCM in your application.

<img width="700px" src="images/quickstart/create_choose_app.png">
Follow the steps under **Use the Firebase Assistant** in the [Firebase Developers Guide](https://firebase.google.com/docs/android/setup). Once you connect and sync to Firebase successfully, you will be able to download the `google-services.json` for your application.

Login to Firebase console and make a note of generated `Server API Key` and `Sender ID` in your notepad. You will need them in the next step.

Save the generated `Server API Key` and `Sender ID` in your notepad. You will need them in the next step.
<img width="700px" src="images/quickstart/server_key_sender_id.png">"

<img width="700px" src="images/quickstart/save_server_api_key.png">"
Make sure the generated `google-services.json` is downloaded to the `app` directory of the quickstart project to replace the existing `app/google-services.json` stub json file. If you are using the Firebase plugin make sure to remove the stub `google-services.json` file first.

Copy the generated `google-services.json` into the `/app` directory of the quickstart project to replace the existing `/app/google-services.json` .
As a final step re-run the application from Android Studio to ensure the APK now has the latest `google-services.json` file.

### <a name="bullet8"></a>8. Add a Push Credential using your FCM `Server API Key`

### <a name="bullet8"></a>8. Add a Push Credential using your GCM `Server API Key`

You will need to store the GCM `Server API Key` with Twilio so that we can send push notifications to your app on your behalf. Once you store the API Key with Twilio it will get assigned a Push Credential SID so that you can later specify which key we should use to send push notifications.
You will need to store the FCM `Server API Key` with Twilio so that we can send push notifications to your app on your behalf. Once you store the API Key with Twilio, it will get assigned a Push Credential SID so that you can later specify which key we should use to send push notifications.

Go to the Push Credentials page and create a new Push Credential.

Paste in the `Server API Key` and press Save.

<img width="700px" src="images/quickstart/add_push_cred.png">"
<img width="700px" src="images/quickstart/add_fcm_push_cred.png">"

### <a name="bullet9"></a>9. Receiving an Incoming Notification

Expand All @@ -134,8 +128,6 @@ Once you’ve done that, restart the server so it uses the new configuration inf





## Reducing APK Size

Our library is built using native libraries. As a result, if you use the default gradle build you will generate an APK with all four architectures(armeabi-v7a, arm64-v8a, x86, x86_64) in your APK.
Expand All @@ -147,17 +139,6 @@ The following snippet shows an example `build.gradle` with APK splits enabled.
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.2"

defaultConfig {
applicationId "com.twilio.voice.quickstart"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}

// Specify that we want to split up the APK based on ABI
splits {
abi {
Expand All @@ -176,9 +157,6 @@ The following snippet shows an example `build.gradle` with APK splits enabled.
}
}

dependencies {
compile 'com.twilio:voice-android:2.0.0-beta4'
}

The adoption of APK splits requires developers to submit multiple APKs to the Play Store. Refer to [Google’s documentation](https://developer.android.com/google/play/publishing/multiple-apks.html) for how to support this in your application.

Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
applicationId "com.twilio.voice.quickstart"
minSdkVersion 16
targetSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
Expand Down Expand Up @@ -40,12 +40,12 @@ android {

dependencies {
testCompile 'junit:junit:4.12'
compile 'com.twilio:voice-android:2.0.0-beta4'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:appcompat-v7:24.2.1'
compile "com.google.android.gms:play-services-gcm:9.4.0"
compile 'com.twilio:voice-android:2.0.0-beta5'
compile 'com.android.support:design:25.1.1'
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.koushikdutta.ion:ion:2.1.8'
compile 'com.google.firebase:firebase-messaging:10.0.1'
}

apply plugin: 'com.google.gms.google-services'
2 changes: 1 addition & 1 deletion app/google-services.json
@@ -1,4 +1,4 @@
//Follow the steps in https://developers.google.com/mobile/add to generate your own google-services.json file.
// Follow the steps in https://developers.google.com/mobile/add to generate your own google-services.json file.
{
"project_info": {
"project_number": "your_project_number",
Expand Down
40 changes: 8 additions & 32 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -2,12 +2,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twilio.voice.quickstart">

<!-- GCM Permissions -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.twilio.voice.quickstart.permission.C2D_MESSAGE" />
<permission android:name="com.twilio.voice.quickstart.permission.C2D_MESSAGE" android:protectionLevel="signature"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -22,41 +16,23 @@
</intent-filter>
</activity>

<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

<category android:name="com.twilio.voice.quickstart" />
</intent-filter>
</receiver>

<!-- [START fcm_listener] -->
<service
android:name=".gcm.VoiceGCMListenerService"
android:exported="false">
android:name=".fcm.VoiceFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<service
android:name=".gcm.VoiceInstanceIDListenerService"
<!-- [END fcm_listener] -->
<!-- [START instanceId_listener] -->
<service
android:name=".fcm.VoiceFirebaseInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>

<service
android:name=".gcm.GCMRegistrationService"
android:exported="false"></service>

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<!-- [END instanceId_listener] -->

</application>
</manifest>
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;

import static android.content.Context.AUDIO_SERVICE;

Expand All @@ -21,15 +22,22 @@ public class SoundPoolManager {
private static SoundPoolManager instance;

private SoundPoolManager(Context context) {

// AudioManager audio settings for adjusting the volume
audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);
actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
volume = actualVolume / maxVolume;

// Load the sounds
soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
int maxStreams = 1;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
soundPool = new SoundPool.Builder()
.setMaxStreams(maxStreams)
.build();
} else {
soundPool = new SoundPool(maxStreams, AudioManager.STREAM_MUSIC, 0);
}

soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
Expand Down Expand Up @@ -78,7 +86,4 @@ public void release() {
}
}

public boolean isRinging() {
return playing;
}
}

0 comments on commit 6d51d35

Please sign in to comment.