Luffy
Luffy可以在手机端实时显示你App中的logcat输出。并且具有Log等级与Tag过滤功能。另外Luffy还支持收集Log,保存Log和查看本地log功能。
使用方法
1.Gradle中添加依赖
dependencies {
...
compile android studio :compile 'com.zql.android:luffy:1.1'
}
2.在manifest中添加如下内容:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.READ_LOGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<activity android:name="com.zql.android.luffy.LuffyView" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="file"/>
<data android:scheme="content"/>
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
<service
android:name="com.zql.android.luffy.LuffyService"
android:enabled="true"
android:exported="false"
android:process=":remote">
</service>
3.如果设备是Android M或以上,请在MainActivity中添加如下内容用于进行权限申请(针对runtime permission):
public static final int OVERLAY_PERMISSION_REQ_CODE = 370 ;
public void requestPermission(){
// Here, this Activity is the current activity
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
Toast.makeText(this,"please give me the permission",Toast.LENGTH_SHORT).show();
} else {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
10);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
switch (requestCode) {
case 10: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
}
return;
}
}
}
public void requestDrawOverlays(){
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}
@SuppressLint("NewApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("luffy","onActivityResult" + requestCode + " " + resultCode) ;
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
if (Settings.canDrawOverlays(this)) {
sendStartBroadcast();
}
}
}
并且在MainActivity的onCreate中添加如下方法:
requestPermission(); //主动进行权限申请
4.通过以下接口使用Luffy
/**
* 启动Luffy窗口和log收集
* @param activity
* @param tags 自定义tag
*/
public static void try2StartLuffy(Activity activity,String[] tags){}
/**
* 移除Luffy窗口,但不停止log收集
* @param activity
*/
public static void stopLuffy(Activity activity)
/**
* 只启动Log收集,不启动窗口
* @param activity
*/
public static void justStartCollectLog(Activity activity){}
/**
*
* @param activity
*/
public static void stopLuffyAndSaveLog(Activity activity)
5. log文件会被保存在sdcard下的luffy文件夹内。
6. 部分截图
更新日志
1.1
-添加静默log抓取和保存功能(文件保存在sdcard/luffy下)
-添加LuffyView查看本地log文件,支持TAG过滤
1.0
-通过Luffy窗口显示App的Log并提供等级和TAG过滤方法。