TC70 logging crash to file with logcat

We used the following code to log crashes of out app to a logfile:

 

public class App extends Application {

 

   @Override
   public void onCreate() {

 

int stringId = this.getApplicationInfo().labelRes;

String appName = this.getString(stringId);

final String fn = getExternalCacheDir() + "/" + appName + "-log.txt";

File filename = new File(fn);

cmd = "logcat -v time -n 2 -r 1024 -f " + filename.getAbsolutePath();

 

try {

   p = Runtime.getRuntime().exec(cmd);

} catch (IOException e) {
   e.printStackTrace();

}

   }

 

}
The logfile is stored in folder /storage/sdcard0/Android/data/com.tup.crashreport/cache. We developed under Android 4.4.3 on TC50 and everything works as designed.
With TC70 under Android 4.4.2 the logfile is not created (only the folder) and we got the warning "W/ContextImpl: Failed to ensure directory: /storage/sdcard0/Android/data/com.tup.crashreport/cache".
Why does TC70 fail to store the logfile?

Pietro Francesc...
Hi Klaus,Is your application

Hi Klaus,

Is your application asking for the permission to write to the external storage?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

The original build of the TC70, even if based on Android v4.4.2, does have some special settings that make it handle the external storage in a similar way to Android 4.3 and older versions.

So, even if, on Android KK, the permission is not needed to write in your own package folder (I imagine that your app package is com.tup.crashreport), you may need that setting on the original TC70 BSP.

My suggestion would be to update your TC70 to a newer build if this can be an option.

Best regards

~Pietro

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Klaus Heim
Hi Pietro,the permission to

Hi Pietro,

the permission to write is granted in the Manifest.xml file. I found the solution: change the logcat command

cmd = "logcat -vtime -f " + filename.getAbsolutePath() + " -n2 -r1024";

and it works.

Thank you for your tip.

Best regards

Klaus

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Log in to post comments