├── .gitignore ├── .idea ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── guaju │ │ └── screenrecordlibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── guaju │ │ │ └── screenrecordlibrary │ │ │ ├── MainActivity.java │ │ │ └── MyApplication.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── guaju │ └── screenrecordlibrary │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenrecorderlibrary ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── guaju │ │ └── screenrecorderlibrary │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── guaju │ │ │ └── screenrecorderlibrary │ │ │ ├── RecordService.java │ │ │ ├── RecordStatus.java │ │ │ └── ScreenRecorderHelper.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── guaju │ └── screenrecorderlibrary │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 1.8 38 | 39 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScreenRecordLibrary 2 | 本库是基于MediaProjection封装的手机屏幕录制开源库,并提交到Jcenter,方便大家使用 3 | 4 | 使用方法: 5 | 6 | module中的build.gradle中的depandencies中添加依赖即可,如下 7 | dependencies { 8 | xxxxxx 9 | compile 'com.guaju:screenrecorderlibrary:1.0.1' 10 | } 11 | 12 | 目前最新的版本是1.0.1,仅仅是朋友用了用,如果大家使用过程中有什么意见和建议,欢迎issue 13 | 14 | 使用方法: 15 | 16 | 1、添加权限,注册service 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 2、在application中初始化实例 27 | 28 | 如: 29 | private ScreenRecorderHelper instance; 30 | public static MyApplication app; 31 | @Override 32 | public void onCreate() { 33 | super.onCreate(); 34 | app=this; 35 | //init 36 | instance = ScreenRecorderHelper.getInstance(this); 37 | } 38 | public ScreenRecorderHelper getSRHelper(){ 39 | return instance; 40 | } 41 | 得到ScreenRecorderHelper类 42 | 43 | 并且别忘记在清单文件中配置 application name 44 | 45 | 46 | 47 | 48 | 3、在需要录屏的activity 或者fragment中初始化RecordService,如 49 | 50 | srHelper = MyApplication.getApp().getSRHelper(); 51 | 52 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 53 | isclick=true; 54 | srHelper.initRecordService(this); 55 | } 56 | 由于我这个库只考虑到了5.0之后的,所以如果有5.0版本之前的手机需要录屏的话,请自行处理 57 | 58 | 4、复写onActivityResult方法,我在screenRecorderHelper中也定义了一个onActivityResult方法,直接拿来使用即可,如 59 | 60 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 61 | super.onActivityResult(requestCode, resultCode, data); 62 | 63 | Log.e("tag", "requestCode****" + requestCode); 64 | srHelper.onActivityResult(this, requestCode, resultCode, data, new ScreenRecorderHelper.OnRecordStatusChangeListener() { 65 | @Override 66 | public void onChangeSuccess() { 67 | //开始录制,处理开始录制后的事件 68 | dosomething 69 | } 70 | 71 | @Override 72 | public void onChangeFailed() { 73 | //如果录制失败,则不作任何变化 74 | dosomething 75 | } 76 | }); 77 | } 78 | 79 | 5.准备工作就绪,直接操作开始录制按钮,和停止录制按钮即可 80 | 81 | srHelper.startRecord(MainActivity.this); 82 | 83 | srHelper.stopRecord(new ScreenRecorderHelper.OnRecordStatusChangeListener() { 84 | @Override 85 | public void onChangeSuccess() { 86 | //当停止成功,做界面变化 87 | //Toast.makeText(MainActivity.this, "录屏成功"+srHelper.getRecordFilePath(), Toast.LENGTH_SHORT).show(); 88 | 89 | } 90 | 91 | @Override 92 | public void onChangeFailed() { 93 | //不作处理 94 | 95 | } 96 | }); 97 | 98 | ok,走完上边五步就能够实现屏幕录制了,当然如果想改下代码的话,可以下载module库直接修改,多谢指教~~~ 99 | 100 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.guaju.screenrecordlibrary" 7 | minSdkVersion 14 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | buildToolsVersion '26.0.2' 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile 'com.android.support:appcompat-v7:26.0.0-beta1' 25 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 26 | compile project(':screenrecorderlibrary') 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/guaju/screenrecordlibrary/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.guaju.screenrecordlibrary; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.guaju.screenrecordlibrary", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/guaju/screenrecordlibrary/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.guaju.screenrecordlibrary; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.Toast; 10 | 11 | import com.guaju.screenrecorderlibrary.ScreenRecorderHelper; 12 | 13 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 14 | 15 | private Button bt_start,bt_stop; 16 | private ScreenRecorderHelper srHelper; 17 | 18 | 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_main); 24 | initView(); 25 | srHelper = MyApplication.getApp().getSRHelper(); 26 | srHelper.initRecordService(this); 27 | 28 | 29 | } 30 | 31 | private void initView() { 32 | bt_start = findViewById(R.id.bt_start); 33 | bt_stop = findViewById(R.id.bt_stop); 34 | bt_start.setOnClickListener(this); 35 | bt_stop.setOnClickListener(this); 36 | } 37 | 38 | @Override 39 | public void onClick(View v) { 40 | if (v.getId()==R.id.bt_start){ 41 | srHelper.startRecord(this); 42 | }else if (v.getId()==R.id.bt_stop){ 43 | srHelper.stopRecord(new ScreenRecorderHelper.OnRecordStatusChangeListener() { 44 | @Override 45 | public void onChangeSuccess() { 46 | //当停止成功,做界面变化 47 | bt_start.setText("开始录制"); 48 | Toast.makeText(MainActivity.this, "录屏成功"+srHelper.getRecordFilePath(), Toast.LENGTH_SHORT).show(); 49 | } 50 | 51 | @Override 52 | public void onChangeFailed() { 53 | //不作处理 54 | 55 | } 56 | }); 57 | } 58 | } 59 | 60 | @Override 61 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 62 | srHelper.onActivityResult(this, requestCode, resultCode, data, new ScreenRecorderHelper.OnRecordStatusChangeListener() { 63 | @Override 64 | public void onChangeSuccess() { 65 | //控制开始按钮的文字变化 66 | bt_start.setText("正在录制"); 67 | } 68 | 69 | @Override 70 | public void onChangeFailed() { 71 | //如果录制失败,则不作任何变化 72 | bt_start.setText("开始录制"); 73 | } 74 | }); 75 | } 76 | 77 | 78 | 79 | @Override 80 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 81 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 82 | srHelper.onRequestPermissionsResult(this,requestCode,permissions,grantResults); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/guaju/screenrecordlibrary/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.guaju.screenrecordlibrary; 2 | 3 | import android.app.Application; 4 | 5 | import com.guaju.screenrecorderlibrary.ScreenRecorderHelper; 6 | 7 | /** 8 | * Created by guaju on 2017/12/29. 9 | */ 10 | 11 | public class MyApplication extends Application { 12 | 13 | private ScreenRecorderHelper instance; 14 | public static MyApplication app; 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | app=this; 19 | //init 20 | instance = ScreenRecorderHelper.getInstance(this); 21 | } 22 | 23 | public ScreenRecorderHelper getSRHelper(){ 24 | return instance; 25 | } 26 | public static MyApplication getApp(){ 27 | return app; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 |