System.getProperty("java.class.path") | System.getProperty("java.class.version") | System.getProperty("os.version") | |
---|---|---|---|
Android 애뮬 | . | 50.0 | 4.14.112+ |
LDplayer(애뮬) | . | 50.0 | 4.0.9 |
휴대폰(galaxy s10e) | . | 50.0 | 4.14.133-1924513 |
이를 통해서 어제와 비슷한 방법으로 button을 만들어내면
https://velog.io/@khw970421/Android-Studio-%EC%95%A0%EB%AE%AC%EB%A0%88%EC%9D%B4%ED%84%B0%EC%99%80-%EC%95%84%EB%8B%8C%EA%B2%83-%ED%83%90%EC%A7%80%ED%95%98%EA%B8%B0-%EB%B0%A9%EB%B2%951
public static void check1(MainActivity num)
{
String properties = System.getProperty("os.version");
if(properties.equals("4.0.9")||properties.equals("4.14.112+")) //ldplayer이거나 android studio 애뮬일경우
Toast.makeText(num,"애뮬입니다.",Toast.LENGTH_LONG).show();
else
Toast.makeText(num,"애뮬이 아닙니다.",Toast.LENGTH_LONG).show();
}
이렇게 코드를 추가를 했다.
그러니 휴대폰에서 작동할때는 버튼을 누르면 애뮬이 아니라고 뜨고
그외의 ldplayer와 android studio 애뮬에서는 애뮬이라고 뜬다.
package com.example.myapplication;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import java.util.Properties;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
Button button;
Button button1;
@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);
}
});
button1 = findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
check1(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();
}
public static void check1(MainActivity num)
{
String properties = System.getProperty("os.version");
if(properties.equals("4.0.9")||properties.equals("4.14.112+"))
Toast.makeText(num,"애뮬입니다.",Toast.LENGTH_LONG).show();
else
Toast.makeText(num,"애뮬이 아닙니다.",Toast.LENGTH_LONG).show();
}
}
<?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="156dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="@+id/textView"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintHorizontal_bias="0.494"
app:layout_constraintStart_toStartOf="@+id/textView" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="72dp"
android:text="Button1"
app:layout_constraintBottom_toBottomOf="@+id/textView"
app:layout_constraintEnd_toStartOf="@+id/textView"
app:layout_constraintHorizontal_bias="0.838"
app:layout_constraintStart_toStartOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
=> 중요포인트 <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>