android 如何在Unity应用程序中防止视频录制或屏幕录制?

jutyujz0  于 2023-04-18  发布在  Android
关注(0)|答案(1)|浏览(255)

我做了一个Java类和绑定与Unity主活动.如果我采取截图然后代码工作正常,但当我下载任何屏幕录制应用程序和运行应用程序,然后它不工作.但这段代码与Android原生应用程序工作正常.此外,我搜索了许多帖子,但没有找到任何帮助我,所以我创建了这篇文章.
这是我的Maimainfest文件代码

<activity android:name="com.unity3d.player.StopRecoding"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <action android:name="android.intent.action.VIEW" />
  </intent-filter>
</activity>

这是我的java代码

mUnityPlayer = new UnityPlayer(this);  
 getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_SECURE,
 android.view.WindowManager.LayoutParams.FLAG_SECURE);

 setContentView(mUnityPlayer);Toast.makeText(this, "Activity bind succsesfuly", Toast.LENGTH_SHORT).show();

}
catch(Exception e)
{
Toast.makeText(this, "Activity bind faild " + 
e.getMessage(),Toast.LENGTH_SHORT).show();
}
ws51t4hk

ws51t4hk1#

这分为两个步骤:
1 Create a custom activity

getWindow().setFlags(LayoutParams.FLAG_SECURE,LayoutParams.FLAG_SECURE);

package my.package;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.*;

public class SafetyActivity extends UnityPlayerActivity {
@Override      
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
  }
}

2 Create a custom android manifest

〈activity android:name=“my.package.SafetyActivity”

<?xml version="1.0" encoding="utf-8"?> <manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.unity3d.player"
    xmlns:tools="http://schemas.android.com/tools">
    <application>
        <activity android:name="my.package.SafetyActivity"
                  android:theme="@style/UnityThemeSelector">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
        </activity>
    </application> </manifest>

相关问题