我的应用程序只有MainActivity一个ImageView.
BroadcastReceiver作品。当我连接 USB 时显示 Toast 消息。
现在,我需要启动我的应用程序最小化并只显示应用程序连接了 USB 电缆。
BroadcastReceiver broadcast_reciever = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent intent) {
String action = intent.getAction();
if (action.equals("usb_detect")) {
Toast.makeText(arg0,"Atenção!",Toast.LENGTH_SHORT).show();
finish();
startActivity(getIntent());
//startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER));
}
}
};