Intent를 이용해서 전화 및 화상 통화 호출하는 방법

|

Intent를 이용해서 전화 및 화상 통화 호출하는 방법

제조사마다 방식이나 특정 Flag 값이 다를 수 있습니다.

import android.Manifest.permission;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

  EditText etPhoneNumber;
  static final int PERMISSION_REQUEST_CODE = 100;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    etPhoneNumber = findViewById(R.id.et_phone_number);

    findViewById(R.id.btn_call).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent i = new Intent(Intent.ACTION_CALL);
        i.setData(Uri.parse("tel:" + getPhoneNumber()));
        i.putExtra("android.phone.extra.calltype", 0);
        startActivity(i);
      }
    });

    findViewById(R.id.btn_video_call).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent i = new Intent(Intent.ACTION_CALL);
        i.setData(Uri.parse("tel:" + getPhoneNumber()));
        i.putExtra("videocall", true);
        startActivity(i);
      }
    });

    if (checkSelfPermission(permission.CALL_PHONE)
        != PackageManager.PERMISSION_GRANTED) {
      String[] permissions = new String[]{permission.CALL_PHONE};
      requestPermissions(permissions, PERMISSION_REQUEST_CODE);
    }
  }

  String getPhoneNumber() {
    return etPhoneNumber.getText().toString();
  }

  @Override
  public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    switch (requestCode) {
      case PERMISSION_REQUEST_CODE:
        if (grantResults.length > 0
            && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
          Toast.makeText(getApplicationContext(), "Permission 완료", Toast.LENGTH_SHORT).show();
        } else {
          Toast.makeText(getApplicationContext(), "Permission 실패", Toast.LENGTH_SHORT).show();
        }
        break;
    }
  }

}

ZSH Plug-in 사용 방법

|

ZSH Plug-in 사용 방법

ZSH에는 수 많은 플러그인(Plug-in) 들이 있습니다. 그런데, 그 중에서 쓸만한 것들이 아주 많은 것 같지는 않습니다. 다음은 개인적으로 쓰고 있는, 범용적으로 쓰일 수 있는 플러그인들입니다.

ZSH 플러그인 설치는 ~/.oh-my-zsh/custom/plugins 디렉토리에 하면 되며, 사용 유무는 ~/.zshrc 파일에서 설정 할 수 있습니다.


플러그인 설치 예시

cd ${ZSH_CUSTOM1:-$ZSH/custom}/plugins

git clone https://github.com/djui/alias-tips.git
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

그 이후 ~/.zshrc 파일에 다음과 같이 설정합니다.

plugins=(
  git
  alias-tips
  zsh-autosuggestions
  zsh-syntax-highlighting
)

그 외에도 저는 wd 같은 플러그인도 사용하고 있습니다.

ZSH 기본 설정 변경

|

ZSH 기본 설정 변경

ZSH 기본 설정은 ~/.zshrc 파일에서 세팅할 수 있습니다. ~/.zshrc 파일은 터미널을 처음 실행했을 때 실행되는 환경 변수 파일이기도 합니다. (.bashrc 파일과 유사)


기본 테마를 agnoster로 변경

~/.zshrc 파일을 열어서 다음과 같이 변경합니다. 기본 값은 ZSH_THEME="robbyrussell" 입니다.

ZSH_THEME="agnoster"

만약 실행할 때마다 랜덤으로 테마를 변경하고 싶으면 다음과 같이 설정할 수도 있습니다.

ZSH_THEME="random"


테마 색상(팔레트) 변경

가독성이 좋은 Solarize 색상 테마로 변경하는 방법입니다. 저는 Solarize 색상 테마 안의 Dark Theme를 사용하고 있습니다.

sudo apt-get install dconf-cli

git clone git://github.com/sigurdga/gnome-terminal-colors-solarized.git ~/.solarized
cd ~/.solarized
./install.sh

This script will ask you which color scheme you want, and which Gnome Terminal profile to overwrite.

Please note that there is no uninstall option yet. If you do not wish to overwrite any of your profiles, you should create a new profile before you run this script. However, you can reset your colors to the Gnome default, by running:

    Gnome >= 3.8 dconf reset -f /org/gnome/terminal/legacy/profiles:/
    Gnome < 3.8 gconftool-2 --recursive-unset /apps/gnome-terminal

By default, it runs in the interactive mode, but it also can be run non-interactively, just feed it with the necessary options, see 'install.sh --help' for details.

Please select a color scheme:
1) dark
2) dark_alternative
3) light
#? 1

Please select a Gnome Terminal profile:
1) Unnamed
#? 1
~~~

그런 다음 .zshrc 파일 맨 아래에 아래 항목을 추가합니다.

eval `dircolors ~/.dir_colors/dircolors`

그 다음 터미네이터의 Preferences 에서 Profiles > ColorsBuilt-in schemes 항목을 엽니다. Solarized dark 항목이 추가되어 있는 것을 확인할 수 있습니다.

저는 백그라운드 색을 White on Black으로 설정하며, Palette 항목은 Solarized로 설정하고 있습니다. (Ubuntu 20.04 기준으로는 Foreground and Blackground에서 Built-in schemesWhite on Black, PaletteBuilt-in schemesSolarized로 설정했습니다.)


.zshrc 예제

예제

# 터미널 색상 테마 적용
eval `dircolors ~/.dir_colors/dircolors`

# for (i-search)
stty stop undef

# for Java
export JAVA_HOME=/usr/lib/jvm/java-8-oracle

# for Android
export ANDROID_SDK=~/Android/Sdk
export ANDROID_NDK=~/Android/Ndk/android-ndk-r17b
export ANDROID_HOME=$ANDROID_SDK

export PATH=$PATH:$ANDROID_SDK:$ANDROID_TOOLS:$ANDROID_NDK:$ANDROID_HOME/tools:$ANDROID_SDK/platform-tools

# for TERM setting
export TERM=xterm

# for ZSH AutoSuggestion
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=cyan'

# 프롬프트에서 컴퓨터 이름 삭제
prompt_context() { 
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then 
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER" 
  fi 
}

ZSH 및 Oh! My ZSH 설치하는 방법

|

ZSH 및 Oh! My ZSH 설치하는 방법


terminator 설치(생략 가능)

테마 적용도 하기 쉬운 편이며, ZSH와 잘 어울리는 조합이기 때문에 가급적 terminator를 설치하는 것을 추천합니다.

sudo apt-get update
sudo apt-get install terminator


zsh 설치

sudo apt-get install zsh


Oh My ZSH 설치

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"


Powerline 폰트 설치(생략 가능)

저는 개인적으로 D2Coding Regular를 사용하기 때문에 이 과정은 건너뛰는 편입니다.

wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf
wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf

mkdir ~/.fonts/
mv PowerlineSymbols.otf ~/.fonts/
mkdir -p ~/.config/fontconfig/conf.d 

fc-cache -vf ~/.fonts/
mv 10-powerline-symbols.conf ~/.config/fontconfig/conf.d/

어느 날 갑자기 외장 디스크가 Read Only가 된 경우 해결법

|

어느 날 갑자기 외장 디스크가 Read Only가 된 경우 해결법

어느 날 갑자기 외부 저장 매체가 Read Only 상태가 되어버렸을 때의 현상 수정하는 방법입니다. 아마 불필요하거나 손상된 파일이 많이 생긴 바람에 이런 현상이 생긴 것 같습니다.

터미널에서 다음과 같이 명령을 수행합니다.


경로 확인

$ sudo df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     1.6G  1.9M  1.6G   1% /run
...
/dev/sdd1      vfat      932G   36G  896G   4% /media/snowdeer/PORTABLESSD

여기에서 외장 디스크의 Filesystem 이름과 Mounted 되어있는 경로 이름을 확인합니다.


Unmout

$ sudo umount /media/snowdeer/PORTABLESSD


불필요한 파일 정리

$ sudo dosfsck -a /dev/sdd1

fsck.fat 4.1 (2017-01-24)
0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.
 Automatically removing dirty bit.
/.Trash-1000/files/res
 Start does point to root directory. Deleting dir. 
/.Trash-1000/files/java
 Start does point to root directory. Deleting dir. 
Reclaimed 185 unused clusters (6062080 bytes) in 179 chains.
Free cluster summary wrong (29345789 vs. really 29345582)
  Auto-correcting.
Performing changes.
/dev/sdd1: 440012 files, 1170741/30516323 clusters


불필요한 파일 확인

위 명령어를 수행하면 외장 디스크 루트 디렉토리 안에 수 많은 *.REC 파일들이 생겼음을 확인할 수 있습니다. 해당 파일들을 전부 지우고 파일 탐색 브라우저를 종료했다가 다시 실행하면 Read Only 상태가 해제되었음을 확인할 수 있습니다.