Skip to content

Commit

Permalink
解决安卓11的权限问题
Browse files Browse the repository at this point in the history
solve permission problems on Android 11
  • Loading branch information
w2016561536 committed Nov 27, 2021
1 parent 0983b24 commit fda5a28
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Q1. 大多数情况下,替换前置摄像头的视频需要水平翻转并右旋


Q2. 画面黑屏,相机启动失败?
A2. 目前有些应用并不能成功替换(特别是系统相机)。或者是因为视频路径不对。
A2. 目前有些应用并不能成功替换(特别是系统相机)。或者是因为视频路径不对(是否创建了两级Camera1目录,如`./DCIM/Camera1/Camera1/virtual.mp4`,但只需要一级目录)


Q3. 画面花屏?
Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Q1. The problems of front camera?
A1. In most cases , the video for replacing front camera need to be flipped horizontally and rotated right 90 degrees. The video's resolution **after being processed** need to same with that in toast message. But in some came, it doesn't need to make adjustment, so you need to judge it according to situation.

Q2. Black screen ? Open camera fail ?
A2. Till now ,there are a few apps that can't be hooked, especially the system camera. Or it caused by wrong `Camera1` directory.
A2. Till now ,there are a few apps that can't be hooked, especially the system camera. Or it caused by wrong `Camera1` directory(Whether two levels of Camera1 directory were created, like `./DCIM/Camera1/Camera1/virtual.mp4`, only one level is needed).

Q3. Blurred screen?
A3. The resolution of video is wrong.
Expand Down
2 changes: 1 addition & 1 deletion README_tc.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A1. 前置攝影機方向問題?
Q1.大多數情况下,替換前置攝影機的影片需要水准翻轉並右旋90度,並且影片***處理後***的解析度應與氣泡消息內解析度相同。 但有時這並不需要,具體請根據實際情況判斷。

Q2. 畫面黑屏,相機啟動失敗?
A2. 現時有些應用並不能成功替換(特別是系統相機)。 或者是因為影片路徑不對。
A2. 現時有些應用並不能成功替換(特別是系統相機)。 或者是因為影片路徑不對(是否創建了兩級Camera1目錄,如`./DCIM/Camera1/Camera1/virtual.mp4`,但只需要一級目錄)

Q3. 畫面花屏?
A3. 影片解析度不對。
Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ android {
defaultConfig {
applicationId "com.example.vcam"
minSdk 21
targetSdk 28
versionCode 18
versionName "3.5"
targetSdk 29
versionCode 19
versionName "3.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 18,
"versionName": "3.5",
"versionCode": 19,
"versionName": "3.6",
"outputFile": "app-release.apk"
}
],
Expand Down
39 changes: 25 additions & 14 deletions app/src/main/java/com/example/vcam/HookMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,27 +275,39 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("【VCAM】"+ee.toString());
}
if (toast_content != null){
int auth_statue = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int auth_statue = PackageManager.PERMISSION_DENIED;
try {
auth_statue = toast_content.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
}catch (Exception eee){
auth_statue += (toast_content.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) + 1);
} catch (Exception ignored) {

}
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
auth_statue = toast_content.checkSelfPermission(Manifest.permission.MANAGE_EXTERNAL_STORAGE);
auth_statue += (toast_content.checkSelfPermission(Manifest.permission.MANAGE_EXTERNAL_STORAGE) + 1);
}
}catch (Exception eee){
} catch (Exception ignored) {

}
if ( auth_statue != PackageManager.PERMISSION_GRANTED){
File shown_file = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+lpparam.packageName+"/files/Camera1/" + "has_shown.jpg");
}else {
File DCIM_dic = new File(Environment.getExternalStorageDirectory() + "/DCIM/");
if ((!DCIM_dic.canRead()) && auth_statue < 1){
auth_statue = -1;
}
}
if ( auth_statue < 1 ){
File shown_file = new File(toast_content.getExternalFilesDir(null).getAbsolutePath() + "/Camera1/");
if ((!shown_file.isDirectory()) && shown_file.exists()){
shown_file.delete();
}
if (!shown_file.exists()){
shown_file.mkdir();
}
shown_file = new File(toast_content.getExternalFilesDir(null).getAbsolutePath() + "/Camera1/"+ "has_shown");
if (!(lpparam.packageName.equals(BuildConfig.APPLICATION_ID) || shown_file.exists())) {
Toast.makeText(toast_content, "未授予读取本地目录权限,请检查权限\nCamera1目前重定向为 " + Environment.getExternalStorageDirectory() + "/Android/data/" + lpparam.packageName + "/files/Camera1/", Toast.LENGTH_LONG).show();
String path = Environment.getExternalStorageDirectory()+"/Android/data/"+lpparam.packageName+"/files/Camera1/" ;
Toast.makeText(toast_content, "未授予读取本地目录权限,请检查权限\nCamera1目前重定向为 " + toast_content.getExternalFilesDir(null).getAbsolutePath() + "/Camera1/", Toast.LENGTH_LONG).show();
try {
FileOutputStream fos = new FileOutputStream(path+ "has_shown.jpg");
FileOutputStream fos = new FileOutputStream(toast_content.getExternalFilesDir(null).getAbsolutePath() + "/Camera1/" + "has_shown");
String info = "shown";
fos.write(info.getBytes());
fos.flush();
Expand All @@ -304,13 +316,12 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("【VCAM】"+ e.toString());
}
}
video_path = Environment.getExternalStorageDirectory()+"/Android/data/"+lpparam.packageName+"/files/Camera1/";
video_path = toast_content.getExternalFilesDir(null).getAbsolutePath() + "/Camera1/";
}else {
video_path = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/";
}
}else {
video_path = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/";
}
}else {
video_path = Environment.getExternalStorageDirectory().getPath() + "/DCIM/Camera1/";
}
}
}
Expand Down

0 comments on commit fda5a28

Please sign in to comment.