简体   繁体   中英

Android Wear Message Listener

I need some help I have Android Wear with message api working but I'm stuck sending some commands this is my listener.

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.widget.ImageButton;
import android.widget.Toast;

import com.google.android.gms.wearable.MessageEvent;
import com.google.android.gms.wearable.WearableListenerService;
public class ListenerServiceFromWear extends WearableListenerService {
    private static final String HELLO_WORLD_WEAR_PATH = "/hello-world-wear" ;
    public void onMessageReceived(MessageEvent messageEvent) {
        if (messageEvent.getPath().equals(HELLO_WORLD_WEAR_PATH)) {
            // Toast.makeText(getApplicationContext(),
            //        "Button is clicked", Toast.LENGTH_LONG).show() ;
            Intent startIntent = new Intent(this, MainActivity.class) ;
            // startIntent.putExtra("name",0);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ;
            startActivity(startIntent) ;

        }
        else {
            // android.os.Process.killProcess(android.os.Process.myPid());
        }
    }
}

I want to call the methods of my phone on my code I can initialize the phone class but after that I can't call more methods like : on | off. How do I call methods of the MainActivity class?

I also tried killing the process but the Wear device must close and reopen to respond after that.

Take a look on this ;) best thing ever found for Wear

https://github.com/Mariuxtheone/Teleport

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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