├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── compiler.xml
├── misc.xml
└── workspace.xml
├── .gitignore
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-ldpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── values
│ └── strings.xml
└── layout
│ └── main.xml
├── Android.mk
├── project.properties
├── AndroidAvrcpControllerDemo.iml
├── ant.properties
├── AndroidManifest.xml
├── proguard-project.txt
└── src
└── com
└── example
└── AndroidAvrcpControllerDemo
└── MyActivity.java
/.idea/.name:
--------------------------------------------------------------------------------
1 | AndroidAvrcpControllerDemo
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .classpath
2 | .project
3 | bin/
4 | gen/
5 | local.properties
6 | build.xml
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/denisigo/AndroidAvrcpControllerDemo/HEAD/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/denisigo/AndroidAvrcpControllerDemo/HEAD/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/denisigo/AndroidAvrcpControllerDemo/HEAD/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/denisigo/AndroidAvrcpControllerDemo/HEAD/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH:= $(call my-dir)
2 | include $(CLEAR_VARS)
3 |
4 | LOCAL_MODULE_TAGS := optional
5 |
6 | LOCAL_SRC_FILES := $(call all-java-files-under, src)
7 |
8 | LOCAL_PACKAGE_NAME := AndroidAvrcpControllerDemo
9 |
10 | include $(BUILD_PACKAGE)
11 |
12 | # Use the following include to make our test apk.
13 | include $(call all-makefiles-under,$(LOCAL_PATH))
14 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | AndroidAvrcpControllerDemo
4 |
5 | Play
6 | Stop
7 | Pause
8 | Next
9 | Prev
10 | Get Attrs
11 |
12 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-21
15 |
--------------------------------------------------------------------------------
/AndroidAvrcpControllerDemo.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | Android API 22 Platform
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
11 |
16 |
17 |
20 |
21 |
26 |
27 |
32 |
33 |
38 |
39 |
40 |
41 |
44 |
45 |
50 |
51 |
56 |
57 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/com/example/AndroidAvrcpControllerDemo/MyActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.AndroidAvrcpControllerDemo;
2 |
3 | import android.app.Activity;
4 | import android.bluetooth.*;
5 | import android.os.Bundle;
6 | import android.os.IBinder;
7 | import android.os.RemoteException;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.TextView;
11 |
12 | import java.lang.Override;
13 | import java.util.List;
14 |
15 | public class MyActivity extends Activity {
16 | private static final String TAG = "AndroidAvrcpControllerDemo";
17 |
18 | private BluetoothAvrcpController mAvrcpController;
19 | private TextView mStatusView;
20 | private TextView mAttrsView;
21 |
22 | @Override
23 | public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.main);
26 | mStatusView = (TextView)findViewById(R.id.status);
27 | mAttrsView = (TextView)findViewById(R.id.attrs);
28 |
29 | BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
30 | bluetoothAdapter.getProfileProxy(this, mAvrcpServiceListener, BluetoothProfile.AVRCP_CONTROLLER);
31 | mStatusView.setText("Connecting to the AVRCP_CONTROLLER service");
32 | }
33 |
34 | @Override
35 | protected void onDestroy() {
36 | super.onDestroy();
37 | BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
38 | mAvrcpController.removeCallback();
39 | bluetoothAdapter.closeProfileProxy(BluetoothProfile.AVRCP_CONTROLLER, mAvrcpController);
40 | }
41 |
42 | private BluetoothProfile.ServiceListener mAvrcpServiceListener = new BluetoothProfile.ServiceListener(){
43 | @Override
44 | public void onServiceConnected(int profile, BluetoothProfile proxy) {
45 | if (profile == BluetoothProfile.AVRCP_CONTROLLER){
46 | mStatusView.setText("AVRCP_CONTROLLER connected");
47 | Log.d(TAG, "AvrcpControllerService connected");
48 |
49 | mAvrcpController = (BluetoothAvrcpController) proxy;
50 | mAvrcpController.setCallback(new AvrcpControllerCallback());
51 |
52 | mStatusView.append("\r\nAvrcp devices: \r\n");
53 | List devices = mAvrcpController.getConnectedDevices();
54 | for (BluetoothDevice device : devices)
55 | mStatusView.append(" - " + device.getName() + " " + device.getAddress()+"\r\n");
56 | }
57 | }
58 |
59 | @Override
60 | public void onServiceDisconnected(int profile) {
61 | if (profile == BluetoothProfile.AVRCP_CONTROLLER) {
62 | mStatusView.setText("AVRCP_CONTROLLER disconnected");
63 | Log.d(TAG, "AvrcpControllerService disconnected");
64 | mAvrcpController.removeCallback();
65 | mAvrcpController = null;
66 | }
67 | }
68 | };
69 |
70 | private void sendCommand(int keyCode){
71 | if (mAvrcpController == null)
72 | return;
73 |
74 | List devices = mAvrcpController.getConnectedDevices();
75 | for (BluetoothDevice device : devices){
76 | Log.d(TAG, "send command to device: " + device.getName() + " " + device.getAddress());
77 | mAvrcpController.sendPassThroughCmd(device, keyCode, BluetoothAvrcp.PASSTHROUGH_STATE_PRESS);
78 | mAvrcpController.sendPassThroughCmd(device, keyCode, BluetoothAvrcp.PASSTHROUGH_STATE_RELEASE);
79 | }
80 | }
81 |
82 | public void onPlayButtonClick(View view){
83 | sendCommand(BluetoothAvrcp.PASSTHROUGH_ID_PLAY);
84 | }
85 |
86 | public void onStopButtonClick(View view){
87 | sendCommand(BluetoothAvrcp.PASSTHROUGH_ID_STOP);
88 | }
89 |
90 | public void onPauseButtonClick(View view){
91 | sendCommand(BluetoothAvrcp.PASSTHROUGH_ID_PAUSE);
92 | }
93 |
94 | public void onNextButtonClick(View view){
95 | sendCommand(BluetoothAvrcp.PASSTHROUGH_ID_FORWARD);
96 | }
97 |
98 | public void onPrevButtonClick(View view){
99 | sendCommand(BluetoothAvrcp.PASSTHROUGH_ID_BACKWARD);
100 | }
101 |
102 | public void onGetAttrsButtonClick(View view){
103 | if (mAvrcpController == null)
104 | return;
105 |
106 | int[] attrs = {BluetoothAvrcp.MEDIA_ATTR_TITLE,
107 | BluetoothAvrcp.MEDIA_ATTR_ARTIST,
108 | BluetoothAvrcp.MEDIA_ATTR_ALBUM,
109 | BluetoothAvrcp.MEDIA_ATTR_PLAYING_TIME,
110 | BluetoothAvrcp.MEDIA_ATTR_NUM_TRACKS,
111 | BluetoothAvrcp.MEDIA_ATTR_TRACK_NUM,
112 | };
113 | List devices = mAvrcpController.getConnectedDevices();
114 | for (BluetoothDevice device : devices){
115 | Log.d(TAG, "send getAttrs to device: " + device.getName() + " " + device.getAddress());
116 | mAvrcpController.getElementAttr(device, attrs.length, attrs);
117 | }
118 | }
119 |
120 | private class AvrcpControllerCallback extends IBluetoothAvrcpControllerCallback.Stub {
121 |
122 | private static final String TAG = "AvrcpControllerCallback";
123 |
124 | @Override
125 | public IBinder asBinder() {
126 | return this;
127 | }
128 |
129 | @Override
130 | public void onGetElementAttrRsp(final int numAttr, final int[] attrs, final String[] values) throws RemoteException {
131 | runOnUiThread(new Runnable() {
132 | @Override
133 | public void run() {
134 | mAttrsView.setText("");
135 | for (int i = 0; i < numAttr; i++) {
136 | if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_TITLE)
137 | mAttrsView.append("Title: " + values[i] + "\r\n");
138 | else if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_ARTIST)
139 | mAttrsView.append("Artist: " + values[i] + "\r\n");
140 | else if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_ALBUM)
141 | mAttrsView.append("Album: " + values[i] + "\r\n");
142 | else if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_GENRE)
143 | mAttrsView.append("Genre: " + values[i] + "\r\n");
144 | else if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_NUM_TRACKS)
145 | mAttrsView.append("Num tracks: " + values[i] + "\r\n");
146 | else if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_TRACK_NUM)
147 | mAttrsView.append("Track num: " + values[i] + "\r\n");
148 |
149 | else if (attrs[i] == BluetoothAvrcp.MEDIA_ATTR_PLAYING_TIME)
150 | mAttrsView.append("Playing time: " + values[i] + " ms \r\n");
151 |
152 | Log.d(TAG, "onGetElementAttrRsp attr_id:" + attrs[i] + " value: " + values[i]);
153 | }
154 | }
155 | });
156 |
157 | }
158 | }
159 |
160 |
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 | 1444314808271
185 |
186 | 1444314808271
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
--------------------------------------------------------------------------------