반응형
Notice
Recent Posts
Recent Comments
Link
안단테 안단테
핸드폰 통화기록 가져오기(갤럭시) 본문
728x90
반응형
가끔 핸드폰 통화기록으로 통계를 내고 싶을 때가 있을건데.. 그 방법을 한 번 작성해 보려고 합니다.
순서대로 나와있으니 한 번 쭉 따라해보시길 권장합니다 !
1. 안드로이드 스튜디오 필요
https://developer.android.com/studio
통화 기록을 가져오려면 일단 안드로이드 스튜디오가 필요한데 ! 안드로이드만 가능합니다 ! IOS(애플)은 안됩니다 ㅠㅠ
2. 안드로이드 스튜디오 실행
설치 후 안드로이드 스튜디오를 실행시켜 주세요!
3. 새로운 프로젝트 생성 Empty Activity
실행시킨 뒤 New Project -> Empty Activity 선택!
4. Language -> java / Minimum SDK ->API 28: Android 9.0 (Pie)
선택하는 옵션에서 제가 선택한 옵션으로 클릭해주세요~
5. AndroidManifest.xml 수정
<?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.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<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"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Finish를 누르면 각 파일들이 보일텐데 위와 AndroidManifest.xml에 들어가서 위와 같이 수정해주세요.
6. activity_main.xml 수정
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/btnCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="통화 기록 가져오기"></Button>
<EditText
android:id="@+id/edtCall"
android:layout_width="match_parent"
android:layout_height="match_parent"></EditText>
</LinearLayout>
</LinearLayout>
7. MainActivity.java 수정
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.util.Log;
import java.text.SimpleDateFormat;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
Button btnCall;
EditText edtCall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_CALL_LOG}, MODE_PRIVATE);
btnCall = (Button) findViewById(R.id.btnCall);
edtCall = (EditText) findViewById(R.id.edtCall);
btnCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
edtCall.setText(getCallHistory());
String callLog = getCallHistory();
Log.d("test", callLog);
}
});
}
public String getCallHistory(){
String[] callSet = new String[] { CallLog.Calls.DATE, CallLog.Calls.TYPE, CallLog.Calls.NUMBER, CallLog.Calls.DURATION };
Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, callSet, null, null, null);
if ( c == null)
{
return "통화기록 없음";
}
StringBuffer callBuff = new StringBuffer();
callBuff.append("\n날짜 : 요일 : 시간 : 구분 : 전화번호 : 통화시간\n\n");
c.moveToFirst();
do{
long callDate = c.getLong(0);
SimpleDateFormat datePattern = new SimpleDateFormat("yyyy-MM-dd : E요일 : HH:mm:ss");
String date_str = datePattern.format(new Date(callDate));
callBuff.append(date_str + " : ");
if (c.getInt(1) == CallLog.Calls.INCOMING_TYPE)
{
callBuff.append("수신 : ");
}
else if (c.getInt(1) == CallLog.Calls.OUTGOING_TYPE)
{
callBuff.append("발신 : ");
}
else if (c.getInt(1) == CallLog.Calls.MISSED_TYPE)
{
callBuff.append("부재중 : ");
}
else if (c.getInt(1) == CallLog.Calls.REJECTED_TYPE)
{
callBuff.append("종료 : ");
}
callBuff.append(c.getString(2)+ " : ");
callBuff.append(c.getString(3));
callBuff.append("\n");
} while (c.moveToNext());
c.close();
return callBuff.toString();
}
}
8. 자신의 핸드폰 연결
핸드폰을 연결하게 되면 개발자모드로 할건지 물을텐데 확인을 클릭해 주세요!
9. 실행
안드로이드 스튜디오를 실행시키면 자신의 핸드폰에서 통화기록을 볼 수 있는걸 확인할 수 있습니다 !
728x90
반응형
Comments