简体   繁体   English

Android Wear与手机硬件通信

[英]Android Wear Communicate With Phone Hardware

Hi I have this simple code on Android Wear I need a bit of help everything works well if I'm using the phone alone the problem I have is that I taught Android wear will use automatically the Phone hardware for sound and all that good stuff. 嗨我在Android Wear上有这个简单的代码我需要一些帮助一切正常如果我单独使用手机我的问题是我教的Android磨损会自动使用手机硬件的声音和所有好东西。 Here is my test code 这是我的测试代码

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() ;
    }
});

It call the sound but because watches doesn't have speakers won't sound. 它叫声音,但因为手表没有扬声器不会发出声音。 I want the phone to make the sound. 我想要手机发出声音。 Please if someone can help me will be appreciated. 如果有人可以帮助我,将不胜感激。

While Android Wear devices will play sound if a bluetooth headset is attached, if you need sound to play on the phone you need to use the Wearable Data Layer and probably more specifically the Message API to send a message to your phone app. 如果连接了蓝牙耳机,Android Wear设备播放声音,如果您需要在手机上播放声音,则需要使用可穿戴数据层 ,可能还需要使用Message API向您的手机应用发送消息。 Your phone app would implement a WearableListenerService which would be triggered by the incoming message and would play the sound on the phone. 您的手机应用程序将实现WearableListenerService ,该服务将由传入消息触发,并将在手机上播放声音。

Note: it is much more common for Wear apps to vibrate (via the Vibrator to draw attention rather than play sounds on the phone. Many Wear users use the 'Mute connected phone' option to effectively silence their phone so a sound coming from it may be quite unexpected. 注:这是更为常见的磨损应用振动(通过振动提醒人们注意,而不是玩手机上的声音很多Wear用户使用“静音连接的电话”选项来有效沉默的电话,以便来自它发出的声音。非常意外。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM