Android Wear 与 Phone 硬件通信
Android Wear Communicate With Phone Hardware
您好,我在 Android Wear 上有这个简单的代码 我需要一些帮助 如果我单独使用 phone,一切正常 我遇到的问题是我教 Android wear 将自动使用 Phone 硬件来获得声音和所有好的东西。
这是我的测试代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
imageButtonOne = (ImageButton) findViewById(R.id.imageButtonOne);
textviewOne = (TextView) findViewById(R.id.textviewOne);
imageButtonOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textviewOne.setText("Hello World!");
soundOne() ;
}
});
}
public void soundOne() {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone one = RingtoneManager.getRingtone(getApplicationContext(), notification);
one.play();
} catch (Exception e) {
e.printStackTrace();
}
// MediaPlayer media = MediaPlayer.create(this, R.raw.sound_file_1);
// media.start() ;
// Toolkit.getDefaultToolkit().beep() ;
}
});
它会发出声音但是因为手表没有扬声器不会发出声音。我想让 phone 发出声音。如果有人可以帮助我,我将不胜感激。
虽然 Android Wear 设备 将 在连接了蓝牙耳机时播放声音,但如果您需要在 phone 上播放声音,则需要使用Wearable Data Layer and probably more specifically the Message API to send a message to your phone app. Your phone app would implement a WearableListenerService 将由传入消息触发并在 phone 上播放声音。
注意:Wear 应用振动 更常见(通过 Vibrator 引起注意而不是在 phone 上播放声音。许多 Wear 用户使用 'Mute connected phone' 选项来有效地使他们的 phone 静音,因此来自它的声音可能非常意外。
您好,我在 Android Wear 上有这个简单的代码 我需要一些帮助 如果我单独使用 phone,一切正常 我遇到的问题是我教 Android wear 将自动使用 Phone 硬件来获得声音和所有好的东西。 这是我的测试代码
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
imageButtonOne = (ImageButton) findViewById(R.id.imageButtonOne);
textviewOne = (TextView) findViewById(R.id.textviewOne);
imageButtonOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textviewOne.setText("Hello World!");
soundOne() ;
}
});
}
public void soundOne() {
try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone one = RingtoneManager.getRingtone(getApplicationContext(), notification);
one.play();
} catch (Exception e) {
e.printStackTrace();
}
// MediaPlayer media = MediaPlayer.create(this, R.raw.sound_file_1);
// media.start() ;
// Toolkit.getDefaultToolkit().beep() ;
}
});
它会发出声音但是因为手表没有扬声器不会发出声音。我想让 phone 发出声音。如果有人可以帮助我,我将不胜感激。
虽然 Android Wear 设备 将 在连接了蓝牙耳机时播放声音,但如果您需要在 phone 上播放声音,则需要使用Wearable Data Layer and probably more specifically the Message API to send a message to your phone app. Your phone app would implement a WearableListenerService 将由传入消息触发并在 phone 上播放声音。
注意:Wear 应用振动 更常见(通过 Vibrator 引起注意而不是在 phone 上播放声音。许多 Wear 用户使用 'Mute connected phone' 选项来有效地使他们的 phone 静音,因此来自它的声音可能非常意外。