I have a problem with the android wear device I can turn on the camera with the message api by loading turnOn() onCreate on mobile device.
Problem One: I can't open an activity if the phone is locked. Problem Two: I can start only one activity if the phone is unlocked but can't call methods of the phone. The only way I started the camera was starting the MainActivity on the Oncreate() method using the wearListener service.
I want something like this app: https://play.google.com/store/apps/details?id=com.jumpbyte.flashlight
Here is my code: Oncreate method phone
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent() ;
int valor = intent.getIntExtra("parameter",0);
String value = "key" ;
if (valor == 0){
boolean isCameraFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!isCameraFlash) {
showCameraAlert();
} else {
camera = Camera.open();
params = camera.getParameters();
}
if(isFlashlightOn) {
setFlashlightOff();
} else {
setFlashlightOn();
}
}
else{
finish();
}
/* boolean isCameraFlash = getApplicationContext().getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
if(!isCameraFlash) {
showCameraAlert();
} else {
camera = Camera.open();
params = camera.getParameters();
}
if(isFlashlightOn) {
setFlashlightOff();
} else {
setFlashlightOn();
}
*/
}
Listener phone:
private static final String HELLO_WORLD_WEAR_PATH = "/hello-world-wear" ;
public void onMessageReceived(MessageEvent messageEvent) {
if (messageEvent.getPath().equals(HELLO_WORLD_WEAR_PATH)) {
// AudioManager audiomanager ;
// audiomanager = (AudioManager)getSystemService(Context.AUDIO_SERVICE) ;
// audiomanager = (AudioManager)getSystemService(Context.AUDIO_SERVICE) ;
// audiomanager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI) ;
// Toast.makeText(getApplicationContext(), "Volume Up | Vibration Time Increased", Toast.LENGTH_SHORT).show() ;
//light lightOne = new light();
// MainActivity one = new MainActivity() ;
// one.messageone();
// lightOne.on();
// Toast.makeText(getApplicationContext(),
// "Button is clicked", Toast.LENGTH_LONG).show() ;
Intent startIntent = new Intent(this, MainActivity.class) ;
startIntent.putExtra("parameter", 0); //Optional parameters
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) ;
startActivity(startIntent) ;
/* if(isFlashlightOn) {
setFlashlightOff();
} else {
setFlashlightOn();
}
*/
} else {
} } }
Wear main class:
private void sendMessage() {
if (mNode != null && mGoogleApiClient!=null && mGoogleApiClient.isConnected()) {
Wearable.MessageApi.sendMessage(
mGoogleApiClient, mNode.getId(), HELLO_WORLD_WEAR_PATH, null).setResultCallback(
new ResultCallback<MessageApi.SendMessageResult>() {
@Override
public void onResult(MessageApi.SendMessageResult sendMessageResult) {
if (!sendMessageResult.getStatus().isSuccess()) {
Log.e("TAG", "Failed to send message with status code: "
+ sendMessageResult.getStatus().getStatusCode());
}
}
}
);
}else{ } }
protected void onStart() {
super.onStart() ;
if (!mResolvingError) {
mGoogleApiClient.connect() ;
} }
private void resolveNode() {
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).setResultCallback(new ResultCallback<NodeApi.GetConnectedNodesResult>() {
@Override
public void onResult(NodeApi.GetConnectedNodesResult nodes) {
for (Node node : nodes.getNodes()) {
mNode = node ; } }
}) ; }
public void onConnected(Bundle bundle) {
resolveNode();
}
public void onConnectionSuspended(int i) {
//Improve your code
}
public void onConnectionFailed(ConnectionResult connectionResult) {
//Improve your code
}
Can someone help me out with this to problems please I can't find any way to pass those two problems. I want something like this app: https://play.google.com/store/apps/details?id=com.jumpbyte.flashlight