我的 android wear 设备有问题我可以通过在移动设备上加载 turnOn() onCreate 来使用消息 api 打开相机。
问题一:如果手机被锁定,我无法打开活动。问题二:手机解锁时只能启动一项活动,但不能调用手机的方法。我启动相机的唯一方法是使用 wearListener 服务在 Oncreate() 方法上启动 MainActivity。
我想要这样的应用程序:https ://play.google.com/store/apps/details?id=com.jumpbyte.flashlight
这是我的代码: Oncreate 方法电话
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();
}
*/
}
听众电话:
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 {
} } }
穿主类:
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
}
有人可以帮我解决这个问题吗?我找不到任何方法来解决这两个问题。我想要这样的应用程序:https ://play.google.com/store/apps/details?id=com.jumpbyte.flashlight