The program is running on Android Studio.
I want to output the contents of Log.d () of Android program (Java) to the actual Android device.
Currently, we are investigating whether Android internally distinguishes between mouse and trackpad.
By design, when the mouse is connected to an Android device, an arrow cursor appears on the screen and can be operated like a PC. We confirmed that the arrow cursor appears even when the trackpad is connected.
After investigating the method,
I tried to move the sample program because it can be identified with the method MotionEvent.getSource (), but with Log.d, the output is only Logcat, and actually connect the mouse and trackpad to the terminal Cannot check the output.
I would like to display the contents of this Log.d on the screen of the actual Android device, and confirm how.
Reference website: https://techbooster.org/android/application/2449/
Applicable source codepackage jp.study.test4;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.InputDevice;
import android.view.MotionEvent;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
}
@Override
public boolean onTouchEvent (MotionEvent event) {
// Get InputDevice
InputDevice inputDevice = event.getDevice ();
int deviceId = event.getDeviceId ();// Get device ID
int source = event.getSource ();
Log.d ("TouchEvent", "Input Device" + deviceId + "Source:" + source
+ "X:" + event.getX () + ", Y:" + event.getY ());
return true;
}
}
Supplemental information (FW/tool version etc.)
Device used: Huawei nova lite2 (Android8.0 Oreo)
-
Answer # 1
-
Answer # 2
Is it wrong for toast display?
A program that displays toasts when tapping and releasing the screen
Kotlin is the one I wrote in the past, but for referenceoverride fun onTouchEvent (event: MotionEvent): Boolean { var Event = "" when (event.action) { MotionEvent.ACTION_DOWN->Event = "tap" MotionEvent.ACTION_UP->Event = "released" } Toast.makeText (applicationContext, Event, Toast.LENGTH_SHORT) .show () SystemClock.sleep (100) return super.onTouchEvent (event) } Code
-
Answer # 3
How about using a tool called Hyperion-Android as a way to achieve it without much effort? Plug-ins that work with Timber are also available, so just install them and replace Log.d with Timber.d.
Add the following to build.gradle
debugImplementation 'com.willowtreeapps.hyperion: hyperion-core: 0.9.27' debugImplementation 'com.willowtreeapps.hyperion: hyperion-timber: 0.9.27'
Hyperion-Android starts when you shake your device.
-
Answer # 4
Thank you very much for your answers.
I tried each answer and reference, but with the following code, the result of the method was successfully displayed on the actual machine screen.
(I didn't know that TextView can also be used to change the dynamic text display on the screen)package jp.study.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.InputDevice; import android.view.MotionEvent; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private TextView textView; @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); textView = findViewById (R.id.action_source); } @Override public boolean onTouchEvent (MotionEvent event) { // Get InputDevice (instantiate) InputDevice inputDevice = event.getDevice (); // Get device ID int source = event.getSource (); String source_text = Integer.toString (source); textView.setText (source_text); return false; } }
Related articles
- java - questions about the output result of the simple program
- java - i get an error in android build error: can't find symbol
- java - [android] i want to insert two images inside with a circle frame image as the background [xml]
- java - i want to output multiple characters at the same time with the println statement
- change java output text color
- java - the list is added, but the contents are overwritten
- i want to build an android application from ren'py launcher, but i am unable to proceed with an error (java compilation error)
- java - i want to implement a process to delete the contents selected with a radio button from the list
- android - i want to display the contents of arraylist in the alert dialog list
- java - error in android studio
- android - i want to memorize the screen and display its contents
- java - about type conversion of view in android studio
- java - i want to display the input screen and the output result on the same screen
- java - android i want to register multiple screen buttons at once in setonclicklistener
- java - i want to open a site with a fixed url when i tap the icon of the android studio app
- java - [android] receive and display firestore updates in real time
- java - you can have multiple same android activities multiple layers? ?? ??
- java - i want to output an image saved as binary data in a database with jsp
- java - about output of standard input (3 lines or more)
- java - i want to know the reason why the contents of the variable become null
- java - i want to load a kml file into android studio and display the feature data on google map
- java - the timer will stop
- java - android studio data sharing
- java - crash with nullpointerexception when alarm is activated on android o or later
- java - i want to put the data acquired using sqlitedatabase in the text box
- java - i want to dynamically change the color of the entire background in android studio
- java - i want to move an image with ontouchevent in surface view that performs multi-thread processing
- java - i want to make a timer that can set any time
- java - how to play multiple audios in sequence in android studio
- java - android sessiongetinstance () error [send email]
Old, but there was an article like this:
Use Timber + Log4J for Android app log output
If it can be output to a file, I think it is easy to display it.