Skip to content

Commit 53a57fc

Browse files
author
Paul Ruiz
committed
Added a demo for using audio streaming over Ford's AppLink
1 parent a7734fe commit 53a57fc

26 files changed

+1026
-0
lines changed

FordAppLinkAudio/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
.DS_Store

FordAppLinkAudio/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:0.9.+'
9+
}
10+
}
11+
12+
allprojects {
13+
repositories {
14+
mavenCentral()
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apply plugin: 'android'
2+
3+
android {
4+
compileSdkVersion 19
5+
buildToolsVersion "19.1.0"
6+
7+
defaultConfig {
8+
minSdkVersion 14
9+
targetSdkVersion 19
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
buildTypes {
14+
release {
15+
runProguard false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
}
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/PaulTR/Documents/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the ProGuard
5+
# include property in project.properties.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.ptrprograms.fordapplinkaudio" >
4+
5+
<uses-permission android:name="android.permission.BLUETOOTH" />
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
<!-- Required to check if WiFi is enabled -->
8+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
9+
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
10+
11+
<application
12+
android:allowBackup="true"
13+
android:icon="@drawable/ic_launcher"
14+
android:label="@string/app_name"
15+
android:theme="@style/AppTheme" >
16+
<activity
17+
android:name=".Activity.MainActivity"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
26+
<service android:name=".Service.AppLinkService"></service>
27+
28+
<receiver android:name=".Receiver.AppLinkReceiver">
29+
<intent-filter>
30+
<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />
31+
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
32+
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
33+
<action android:name="android.intent.action.BOOT_COMPLETED" />
34+
<action android:name="android.media.AUDIO_BECOMING_NOISY" />
35+
</intent-filter>
36+
</receiver>
37+
38+
</application>
39+
40+
</manifest>
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.ptrprograms.fordapplinkaudio.Activity;
2+
3+
import android.app.Activity;
4+
import android.bluetooth.BluetoothAdapter;
5+
import android.bluetooth.BluetoothDevice;
6+
import android.content.Intent;
7+
import android.os.Bundle;
8+
import android.text.TextUtils;
9+
import android.view.Menu;
10+
import android.view.MenuItem;
11+
12+
import com.ford.syncV4.proxy.SyncProxyALM;
13+
import com.ptrprograms.fordapplinkaudio.R;
14+
import com.ptrprograms.fordapplinkaudio.Service.AppLinkService;
15+
16+
17+
public class MainActivity extends Activity {
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_main);
23+
24+
startSyncProxyService();
25+
}
26+
27+
private void startSyncProxyService() {
28+
boolean isPaired = false;
29+
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
30+
31+
if( btAdapter != null ) {
32+
if( btAdapter.isEnabled() && btAdapter.getBondedDevices() != null && !btAdapter.getBondedDevices().isEmpty() ) {
33+
for( BluetoothDevice device : btAdapter.getBondedDevices() ) {
34+
if( device.getName() != null && device.getName().contains( getString( R.string.device_name ) ) ) {
35+
isPaired = true;
36+
break;
37+
}
38+
}
39+
}
40+
41+
if( isPaired ) {
42+
if( AppLinkService.getInstance() == null ) {
43+
Intent appLinkServiceIntent = new Intent( this, AppLinkService.class );
44+
startService( appLinkServiceIntent );
45+
} else {
46+
SyncProxyALM proxyInstance = AppLinkService.getInstance().getProxy();
47+
if( proxyInstance == null ) {
48+
AppLinkService.getInstance().startProxy();
49+
}
50+
}
51+
}
52+
}
53+
}
54+
55+
private void endSyncProxyInstance() {
56+
if( AppLinkService.getInstance() != null ) {
57+
SyncProxyALM proxy = AppLinkService.getInstance().getProxy();
58+
if( proxy != null ) {
59+
AppLinkService.getInstance().reset();
60+
} else {
61+
AppLinkService.getInstance().startProxy();
62+
}
63+
}
64+
}
65+
66+
@Override
67+
protected void onDestroy() {
68+
endSyncProxyInstance();
69+
super.onDestroy();
70+
}
71+
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.ptrprograms.fordapplinkaudio.Receiver;
2+
3+
import android.bluetooth.BluetoothAdapter;
4+
import android.bluetooth.BluetoothDevice;
5+
import android.content.BroadcastReceiver;
6+
import android.content.Context;
7+
import android.content.Intent;
8+
import android.media.AudioManager;
9+
10+
import com.ptrprograms.fordapplinkaudio.R;
11+
import com.ptrprograms.fordapplinkaudio.Service.AppLinkService;
12+
13+
/**
14+
* Created by PaulTR on 5/31/14.
15+
*/
16+
public class AppLinkReceiver extends BroadcastReceiver {
17+
18+
@Override
19+
public void onReceive(Context context, Intent intent) {
20+
if( intent == null || intent.getAction() == null || context == null )
21+
return;
22+
23+
BluetoothDevice device = intent.getParcelableExtra( BluetoothDevice.EXTRA_DEVICE );
24+
String action = intent.getAction();
25+
26+
Intent serviceIntent = new Intent( context, AppLinkService.class );
27+
serviceIntent.putExtras( intent );
28+
29+
30+
//Should start service
31+
if( action.compareTo(BluetoothDevice.ACTION_ACL_CONNECTED) == 0 &&
32+
device != null &&
33+
device.getName() != null &&
34+
device.getName().contains( context.getString( R.string.device_name ) ) &&
35+
AppLinkService.getInstance() == null )
36+
{
37+
context.startService(serviceIntent);
38+
}
39+
40+
else if( action.equals( Intent.ACTION_BOOT_COMPLETED ) &&
41+
BluetoothAdapter.getDefaultAdapter() != null &&
42+
BluetoothAdapter.getDefaultAdapter().isEnabled() ) {
43+
context.startService(serviceIntent);
44+
45+
}
46+
47+
//Should stop service
48+
else if( action.equals( BluetoothDevice.ACTION_ACL_DISCONNECTED ) &&
49+
device != null &&
50+
device.getName() != null &&
51+
device.getName().contains( context.getString( R.string.device_name ) ) &&
52+
AppLinkService.getInstance() != null )
53+
{
54+
context.stopService( intent );
55+
}
56+
57+
else if( action.equals(BluetoothAdapter.ACTION_STATE_CHANGED ) &&
58+
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_TURNING_OFF &&
59+
AppLinkService.getInstance() != null )
60+
{
61+
context.stopService( serviceIntent );
62+
}
63+
64+
else if( action.equals( AudioManager.ACTION_AUDIO_BECOMING_NOISY ) ) {
65+
context.stopService( serviceIntent );
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)