[英]Execute method(screen flasher) at same time in multiple android device's
我是android編程的新手。 我用多種顏色制作了一個簡單的屏幕閃光器。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myView = findViewById(R.id.my_view);
myView.setBackgroundColor(color);// set initial colour
new Thread(new Runnable() {
public void run() {
while (true) {
try {
Thread.sleep(INTERVAL);
}
catch (InterruptedException e) {
e.printStackTrace();
}
updateColor();
whichColor = !whichColor;
}
}
}).start();
}
private void updateColor() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (whichColor)
myView.setBackgroundColor(Color.YELLOW);
else
myView.setBackgroundColor(Color.BLACK);
}
});
}
我想將此安裝在多台設備上並同步閃光燈。 我想要的是同步所有設備上的閃光燈顏色。 黃色應在所有設備上顯示,並同時在所有設備上變為黑色。 可能嗎? 也許獲取設備的本地時間並在“ x”秒(本地時間)開始該方法?
創建用於不同閃爍的功能。 在此方法內調用函數。
import java.util.Calendar
String CurrentTime = Calendar.getInstance().getTime().toString().trim();
String YourTime = "Enter Your Expected Time here";
int x = 3000; //Start method time in miliseconds
if(CurrentTime.equals("YourTime")){
try {
sleep(x);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Run Your Colour Change function or method here. like
//colorchange(); or myView.setBackgroundColor(Color.YELLOW);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.