System.getProperty("os.name") | System.getProperty("user.name") | System.getProperty("os.arch") | |
---|---|---|---|
Android 애뮬 | linux | root | i686 |
LDplayer(애뮬) | linux | root | i686 |
휴대폰(galaxy s10e) | linux | root | aarch64 |
MainActivity.java
public class MainActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
check(MainActivity.this);
}
});
}
public static void check(MainActivity num)
{
String properties = System.getProperty("os.arch");
if(properties.equals("i686"))
Toast.makeText(num,"애뮬입니다.",Toast.LENGTH_LONG).show();
else
Toast.makeText(num,"애뮬이 아닙니다.",Toast.LENGTH_LONG).show();
}
}
위의 내용에서 중요한 것은 Button을 누르면 os.arch를 통해 얻은 properties를 i686이라는 문자열과 비교하여 맞으면 애뮬이라고 아니면 애뮬이 아니라고 Text가 뜨는 것이다. (문자열 비교 ==가 아니라 equals이다.)
출처 : https://lifeinprogram.tistory.com/19
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="11dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="@+id/textView"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
AndroidManifest.xml
=> 중요포인트 <user-permission android:name ~~ ANSWER_PHONE_CALLS"/> (허가필요)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>