MainActivity.java
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.example.dataextraction;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import com.google.gson.JsonObject;
import org.json.JSONException;
import org.json.JSONObject;
import io.socket.client.IO;
import io.socket.client.Socket;
public class MainActivity extends AppCompatActivity {
String[] permission_list = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_CALENDAR,
Manifest.permission.ACCESS_NETWORK_STATE,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.GET_ACCOUNTS,
Manifest.permission.READ_CONTACTS,
Manifest.permission.READ_CALL_LOG,
Manifest.permission.READ_PHONE_NUMBERS,
Manifest.permission.READ_CONTACTS,
Manifest.permission.READ_CALL_LOG,
Manifest.permission.READ_SMS,
Manifest.permission.ACCESS_WIFI_STATE
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AppOpsManager appOps = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), getPackageName());
boolean granted = (mode == AppOpsManager.MODE_ALLOWED);
if (granted == false)
{
Intent intent = new Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
}
checkPermission();
Intent intent = new Intent(this, LoadingActivity.class);
startActivity(intent);
}
public void checkPermission(){
//현재 안드로이드 버전이 6.0미만이면 메서드를 종료한다.
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return;
for(String permission : permission_list){
//권한 허용 여부를 확인한다.
int chk = checkCallingOrSelfPermission(permission);
if(chk == PackageManager.PERMISSION_DENIED){
//권한 허용을여부를 확인하는 창을 띄운다
requestPermissions(permission_list,0);
}
}
}
}