I have some videos files in a Android directory and I want execute each one using Intent
. So far no problem, however I need save which video is running (log) in my webservice, so that, I make a asynchronous request, using retrofit 1.9.0, after startActivity(intent)
. My problem is: the log is not save in the right order. All logs are save with the same hour.
This is my function:
File sdCardRoot = Environment.getExternalStorageDirectory();
Intent intent = new Intent(Intent.ACTION_VIEW);
for (int i = 0; i < videoListFromDevice.size(); i++) {
if (isFileInDirectory(videoListFromDevice.get(i).name)) {
File file = new File(Environment.getExternalStorageDirectory() + "/Videos/" + videoListFromDevice.get(i).name + ".mp4");
intent.setDataAndType(Uri.fromFile(file), "video/mp4");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
getContext().startActivity(intent);
getPresenter().sendLogVideo(MainPresenter.DEFAULT_NAME, videoListFromDevice.get(i).name);
}
}
Where videoListFromDevice
is a local list of videos.
Can someone help me?
Thanks.
Logs are executed in a task sequence execution, You should use the Log.v(), Log.d(), Log.i(), Log.w(), and Log.e()
methods to Write/Trace logs. You can then view the logs in logcat.
For ex, Declare a TAG constant in your class:
private static final String TAG = "VideoActivity";
and use that in subsequent calls to the log methods.
Something like this: Log.d(TAG, "videoName=" + video);
For more info see Log | Android Documentation
EDIT:
You can fetch logcat
data as follows:
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
StringBuilder log = new StringBuilder();
String data;
while ((data= bufferedReader.readLine()) != null) {
log.append(data);
}
TextView textView = (TextView) findViewById(R.id.textViewlog);
textView.setText(log.toString());
Don't forgot to add permission:
<uses-permission android:name="android.permission.READ_LOGS" />
To get data for particular TAG:
replace logcat -d
with logcat -d -s YourTag