अपने मैनिफ़ेस्ट फ़ाइल दे निम्न अनुमतियों में:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
अपने पहले/लांचर गतिविधि में, सही होने के बाद लाइनों नीचे
super.onCreate(savedInstanceState);
लिखें: यह आपके उपकरण के लिए अपने ऐप की logcat लिखेंगे बाहरी भंडारण
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_PERMISSION_CODE);
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, READ_PERMISSION_CODE);
}
if (isExternalStorageWritable()) {
File appDirectory = new File(Environment.getExternalStorageDirectory() + "/MyAppLog");
File logDirectory = new File(appDirectory + "/log");
File logFile = new File(logDirectory, "logcat" + ".txt");
// create app folder
if (!appDirectory.exists()) {
appDirectory.mkdir();
}
// create log folder
if (!logDirectory.exists()) {
logDirectory.mkdir();
}
// clear the previous logcat and then write the new one to the file
if (logFile.exists()){
logFile.delete();
}
try {
Process process = Runtime.getRuntime().exec("logcat -c");
process = Runtime.getRuntime().exec("logcat -f " + logFile);
} catch (IOException e) {
e.printStackTrace();
}
} else if (isExternalStorageReadable()) {
// only readable
} else {
// not accessible
}
वांछित ईमेल जोड़ने के लिए लॉगकैट भेजने के लिए ता: विधि नीचे जाँच बाहरी भंडारण के लिए लेखन के लिए अनुमतियाँ या दिया जाता है कि क्या नहीं के लिए
public void sendLogcatMail(){
if (isExternalStorageWritable()) {
File appDirectory = new File(Environment.getExternalStorageDirectory() + "/MyAppLog");
File logDirectory = new File(appDirectory + "/log");
File logFile = new File(logDirectory, "logcat" + ".txt");
if (logFile.exists()) {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("vnd.android.cursor.dir/email");
String to[] = {"[email protected]"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(String.valueOf(logFile.toURI())));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Log files");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Send some message along");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
}
}
विधि का उपयोग करें:
/* जांच करें कि क्या बाह्य भंडारण पढ़ने के लिए उपलब्ध है और लिखने */
public static boolean isExternalStorageWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;
}
हम्म धन्यवाद। तो मुझे अपने प्रोजेक्ट में स्रोत जोड़ना होगा या ऐप को फोन पर इंस्टॉल करना होगा। सही? – RoflcoptrException
आपको उनसे पूछना होगा, क्योंकि मैंने उनकी सामग्री का उपयोग नहीं किया है। कम से कम, आप उनके स्रोत कोड को देख सकते हैं कि वे लॉग कैसे पढ़ते हैं। – CommonsWare
हम्म हां मैंने पृष्ठ पर पढ़ा है कि डेवलपर इसका उपयोग कर सकते हैं, लेकिन हालांकि कोई दस्तावेज नहीं है और मुझे नहीं पता कि इसे कैसे शुरू किया जाए। लेकिन धन्यवाद – RoflcoptrException