• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to establish communication between android device and usb

 
NeelNisha Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to establish communication between Android device(Acting as USB Host) and USB for data transfer and receive both
i'v gone through some sites and found some idea ,I have attached code ,Please tell while testing on emulator how can i get USB connectivity,or if i'm testing attached android app directly on
real device then if any error will come then how can i see log cat,I'm not able to understand.Please help
Please advice me also whether attached source code will be helpful for establishing communication between android host device and USB.Please help its urgent

Here the code
<1>

<2>



 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My advice would be to find a real device and simply check whether what this code does is useful for your purposes or not. If you're serious about Android development, then there is no substitute to having an actual device available.
 
NeelNisha Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Reply Ulf !!!
I asked one more question that if I'll be testing my code on real device then how I'll be able to see log cat to trace errors/information,since my real device will be connected to some other device through USB

I have already gone through this link for Window XP

http://developer.android.com/tools/extras/oem-usb.html

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe add a TextView to the main layout, and append all logged messages to that.
 
NeelNisha Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I found this

public class LogTest extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

StringBuilder log=new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
}
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(log.toString());
} catch (IOException e) {
}
}
}


But one confusion is there how I'll find line numbers also and option "logcat -d" will give only debugging messages not error messages,so ow to get error messages of logcat too with line number,if any small code example will be there then please provide and explain
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
logcat never shows line numbers; what benefit would that have? If you create logcat output you know where in the code you are, after all.

option "logcat -d" will give only debugging messages not error messages

That's not what I'm seeing on my device. How did you get that idea?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to experiment with the Android command line, install Jack Palevich's "Terminal Emulator" app.
 
NeelNisha Singh
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to show only my app related all log cat messages,But writ now I'm getting all unnecessary messages

Here is my code

try {

Process process = Runtime.getRuntime().exec("logcat -d");


BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

StringBuilder log=new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line+"\n");
}
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(log.toString());
}
catch (IOException exception)
{
exception.printStackTrace();
}


I have attached output screen shot also,Please help
logcat_output_screenshot.JPG
[Thumbnail for logcat_output_screenshot.JPG]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, on the command line you could just do a "logcat | grep -i <my package name>", but that won't work with Runtime.exec.

The alternative is to change your code so it prints just the lines that have your logging tag, or the package name of your classes. That's one line of code.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic