【发布时间】:2021-09-16 16:59:23
【问题描述】:
例如,我制作了一个 Nodemcu 服务器,主网页上有 3 个链接(192.168.18.100)。 我想尝试的是,当我单击 android 按钮时,无需打开任何新活动即可访问此链接,即我想留在主要活动上。 到目前为止,这是我的代码,但不是我想要的。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button on = (Button) findViewById(R.id.button);
Button off =(Button) findViewById(R.id.button2);
Button pink = (Button) findViewById(R.id.button3);
on.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://192.168.18.100/ir?code=16236607"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_SEND, uri);
startActivity(intent);
}
});
off.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://192.168.18.100/ir?code=16203967"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
pink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("http://192.168.18.100/ir?code=16214167"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
}
【问题讨论】: