keytool MD5 문자열 얻기 - JDK 7 환경

 

=======================================

 

keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android - keypass android

 

=======================================


안드로이드 공부 중에

구글맵 테스트를 위해 구글맵 API 키를 얻으려면 선행 과정으로 MD5 문자열이 필요합니다.


JDK 7 을 설치한 상태에서 MD5 문자열을 얻기 위해 예전처럼 아래와 같이 실행하면

MD5 문장열이 아닌 SHA1 문자열이 나옵니다.


[ Win7 의 경우 ] : 명령 프롬프트에서 cd C:\Users\사용자명\.android

[XP 의 경우 ] : 명령 프롬프트에서 cd C:\Documents and Settings\사용자명\.android


keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android


그 이유는 JDK 7 부터는 기본값으로 SHA1 인증서 지문이 나오도록 바뀌었네요.

(JDK 6 에서는 MD5 인증서 지문이 기본값입니다.)


해결 방법은 -v 옵션을 주면 됩니다.


keytool -v -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android

 

 

-----


결과화면 

// WebViewDemoA3.java

 

package com.example.graphic;

import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewDemoA4 extends Activity {
 private WebView webview;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.webview_demo);
  
  webview = (WebView)this.findViewById(R.id.webview);
  webview.getSettings().setJavaScriptEnabled(true);
  webview.setWebViewClient(new MyWebViewClient());
  
  webview.loadUrl("http://fs1025.mireene.com");
 }
 
 public void onConfigurationChanged(Configuration newConfig){
  super.onConfigurationChanged(newConfig);
 }

 private class MyWebViewClient extends WebViewClient{

  public boolean shouldOverrideUrlLoading(WebView view, String url){
   view.loadUrl(url);   
   return true;
  }
 }
}

 

 

 

 

 

// webview_demo.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

 

 

 

<!-- 매니페스트에 권한 추가!!! -->

<uses-permission android:name="android.permission.INTERNET" />

 

<!-- 화면 모드가 변경될 때 onConfigurationChanged()메소드가 호출되게 하기 위해서
            추가한다.
            3.2 이전 버전에서는 keyboardHidden|orientation
            3.2 부터는 orientation|scrteenSize 로 지정한다. -->
            
            android:configChanges="orientation|screenSize">

 

--------------------------------------------------------------------------------------------------

 

// assets 폴더에 jsalert.html 넣어주자! 코드는 밑과 다음과 같다....

 

 

<html>
<head>
<title>경고창</title>

<body>
<h2>
<a href="javascript:alert('경고창입니다.');"> 경고창 보기</a>
</h2>
</body>
</html>

결과화면 

// WebViewDemoA3.java

 

package com.example.graphic;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Toast;

public class WebViewDemoA3 extends Activity {
 private WebView webview;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.webview_demo);
  
  webview = (WebView)this.findViewById(R.id.webview);
  webview.getSettings().setJavaScriptEnabled(true);
  
  MyWebChromeClient mywebChromeClient = new MyWebChromeClient();  
  webview.setWebChromeClient(mywebChromeClient);
  webview.loadUrl("file:///android_asset/jsalert.html");
 }
 
 private class MyWebChromeClient extends WebChromeClient{

  @Override
  public boolean onJsAlert(WebView view, String url, String message,
    JsResult result) {
   Toast.makeText(WebViewDemoA3.this, message, Toast.LENGTH_SHORT).show();   
   result.confirm();   
   return true;
  }
 }
}

 

 

 

 

 

// webview_demo.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

 

 

 

<!-- 매니페스트에 권한 추가!!! -->

<uses-permission android:name="android.permission.INTERNET" />

 

--------------------------------------------------------------------------------------------------

 

// assets 폴더에 jsalert.html 넣어주자! 코드는 밑과 다음과 같다....

 

 

<html>
<head>
<title>경고창</title>

<body>
<h2>
<a href="javascript:alert('경고창입니다.');"> 경고창 보기</a>
</h2>
</body>
</html>

 

결과화면  

로딩 진행 상태가 보이는가!!!!

 

 

로딩 완료!!! 

// WebViewDemoA2.java

 

package com.example.graphic;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebViewDemoA2 extends Activity {
 private WebView webview;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  setContentView(R.layout.webview_demo);
  
  webview = (WebView)this.findViewById(R.id.webview);
  
  webview.setWebViewClient(new WebViewClient(){

   @Override
   public void onPageFinished(WebView view, String url) {

    super.onPageFinished(view, url);
    setProgressBarIndeterminateVisibility(false);
   }

   @Override
   public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);
    setProgressBarIndeterminateVisibility(true);
   }
   
  });
  
  
  webview.loadUrl("http://fs1025.mireene.com/");
 }
}

 

 

 

 

 

// webview_demo.xml

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

 

 

 

<!-- 매니페스트에 권한 추가!!! -->

<uses-permission android:name="android.permission.INTERNET" />

 

// DialogDemo.java

 

 package com.example.hellow;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class DialogDemo extends Activity{
 Button list, radio, check, dialog1, login, progress, datePickerFragment;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.dialog_demo);

  Button alert = (Button)findViewById(R.id.alert);

  alert.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    new AlertDialog.Builder(DialogDemo.this)
    .setIcon(R.drawable.ic_launcher)
    .setMessage(R.string.dialog_message)
    .setTitle(R.string.dialog_title)
    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int id) {
      Toast.makeText(DialogDemo.this, "OK Button Click", Toast.LENGTH_SHORT).show();
     }
    })
    .setNegativeButton("NO", new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int id) {
      Toast.makeText(DialogDemo.this, "NO Button Click", Toast.LENGTH_SHORT).show();
     }
    })
    //.create()
    .show();    
   }
  });

 


  list = (Button)findViewById(R.id.list);

  list.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    new AlertDialog.Builder(DialogDemo.this)
    .setTitle(R.string.pick_color)
    .setItems(R.array.color_array, new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {

      switch(which){
      case 0 : list.setBackgroundColor(Color.RED); break;
      case 1 : list.setBackgroundColor(Color.GREEN); break;
      case 2 : list.setBackgroundColor(Color.BLUE); break;
      }
     }
    })
    .show();    
   }
  });

 

 

  radio = (Button)findViewById(R.id.radio);

  radio.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    new AlertDialog.Builder(DialogDemo.this)
    .setTitle(R.string.pick_color)
    .setSingleChoiceItems(R.array.color_array, -1, new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which) {

      switch(which){
      case 0 : radio.setBackgroundColor(Color.RED); break;
      case 1 : radio.setBackgroundColor(Color.GREEN); break;
      case 2 : radio.setBackgroundColor(Color.BLUE); break;
      }
     }
    })
    .setNeutralButton("Close", null)
    .show();    
   }
  });

 


  check = (Button)findViewById(R.id.check);

  check.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    new AlertDialog.Builder(DialogDemo.this)
    .setTitle(R.string.pick_color)
    .setMultiChoiceItems(R.array.color_array, null,
      new DialogInterface.OnMultiChoiceClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which, boolean isChecked) {
      String color="";
      if(isChecked){
       if(which == 0){
        check.setBackgroundColor(Color.RED);
        color = "red";
       } else if(which == 1){
        check.setBackgroundColor(Color.GREEN);
        color = "green";
       } else if(which == 2){
        check.setBackgroundColor(Color.BLUE);
        color = "blue";
       }

       Toast.makeText(DialogDemo.this, "color is " + color + "!!!", Toast.LENGTH_SHORT).show();
      } else {
       if(which <= 2){
        check.setBackgroundColor(Color.GRAY);
       }

       Toast.makeText(DialogDemo.this, "color unselected!!!", Toast.LENGTH_SHORT).show();
      }
     }
    })
    .setNeutralButton("Close", null)
    .show();    
   }
  });


  dialog1 = (Button)findViewById(R.id.dialog1);

  dialog1.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    FireMissilesDialogFragment fragment = new FireMissilesDialogFragment();
    Bundle bundle = new Bundle();
    fragment.setContext(DialogDemo.this);
    fragment.onCreateDialog(bundle).show();    
   }
  });


  login = (Button)findViewById(R.id.login);

  login.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    showAlertDialog();
   }
  });
  
  
  
  progress = (Button)findViewById(R.id.progress);

  progress.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    ProgressDialog dialog = new ProgressDialog(DialogDemo.this);
    dialog.setTitle("Indeterminage");
    dialog.setMessage("Please wait while loading...");
    dialog.setIndeterminate(true);
    dialog.setCancelable(true);
    dialog.show();
   }
  });
  
  
  
  datePickerFragment = (Button)findViewById(R.id.datePickerFragment);

  datePickerFragment.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    DatePickerFragment fragment = new DatePickerFragment();
    Bundle bundle = new Bundle();
    fragment.setContext(DialogDemo.this);
    fragment.onCreateDialog(bundle).show();    
   }
  });
 }


 private void showAlertDialog(){
  LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  LinearLayout loginLayout = (LinearLayout) vi.inflate(R.layout.logindialog, null);

  final EditText id = (EditText) loginLayout.findViewById(R.id.id);
  final EditText pw = (EditText) loginLayout.findViewById(R.id.pw);

  new AlertDialog.Builder(this).setTitle("로그인").setView(loginLayout)
  .setNeutralButton("확인", new DialogInterface.OnClickListener(){

   @Override
   public void onClick(DialogInterface dialog, int which) {
    Toast.makeText(DialogDemo.this, "ID : " + id.getText().toString() + "\nPW : " + pw.getText().toString(), Toast.LENGTH_SHORT).show();
   }
  }).show();
 }
}

 

 

// DatePickerFragment.java

 

 package com.example.hellow;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.Toast;

public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
 Context ctx;
 
 public void setContext(Context ctx){
  this.ctx = ctx;
 }

 @Override
 public Dialog onCreateDialog(Bundle savedInstanceState) {
  // Use the current date as the default date in the picker
  final Calendar c = Calendar.getInstance();
  int year = c.get(Calendar.YEAR);
  int month = c.get(Calendar.MONTH);
  int day = c.get(Calendar.DAY_OF_MONTH);

  // Create a new instance of DatePickerDialog and return it
  return new DatePickerDialog(ctx, this, year, month, day);
 }

 public void onDateSet(DatePicker view, int year, int month, int day) {
  Toast.makeText(ctx, year+"/"+month+"/"+day, Toast.LENGTH_SHORT).show();
 }
}

 

 

// FireMissilesDialogFragment.java

 

 package com.example.hellow;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;

public class FireMissilesDialogFragment extends DialogFragment {

 Context ctx;

 public void setContext(Context ctx){
  this.ctx = ctx;

 }

 @Override
 public Dialog onCreateDialog(Bundle savedInstanceState) {
  AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
  builder.setMessage(R.string.dialog_fire_missiles)

  .setPositiveButton("Fire", new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int id) {
    //
   }
  })
  .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int id) {
    //
   }
  });
  return builder.create();
 }
}

 

 

// dialog_demo.xml

 

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/alert"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="simple alert dialog" />
   
    <Button
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="simple list dialog" />
   
    <Button
        android:id="@+id/radio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="simple radio dialog" />
   
    <Button
        android:id="@+id/check"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="simple check dialog" />
   
    <Button
        android:id="@+id/dialog1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_label5" />

    <Button
        android:id="@+id/login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_label6" />
   
    <Button
        android:id="@+id/progress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_label7" />
   
    <Button
        android:id="@+id/datePickerFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btn_label8" />
</LinearLayout>

 

// logindialog.xml

 

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp" >

        <TextView
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="아이디" />

        <EditText
            android:id="@+id/id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="5dp" >

        <TextView
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="비밀번호" />

        <EditText
            android:id="@+id/pw"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:password="true"/>
    </LinearLayout>

</LinearLayout>

 

결과화면

 

 

notiMgr.notify(0, notification); 오류 발생!!!

왜 오류가 나나 했더니 클래스 파일명이

중복되서 그러는 거였다..... ㅜㅜ

 

그러므로 클래스 파일명을 NotificationManagerActivity로 바꾸고 나서 해결.....

// NotificationManagerActivity.java

 

 package com.example.hellow;


import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.*;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class NotificationManagerActivity extends Activity implements View.OnClickListener {
 NotificationManager notiMgr;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.notification);
  
  notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  
  Button button = (Button)findViewById(R.id.button);
  button.setOnClickListener(this);
 }
 
 public void onClick(View v){
  Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:0101234567"));
  
  PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
  
  Notification notification = new Notification(R.drawable.ic_launcher, "전화", System.currentTimeMillis());
  
  notification.setLatestEventInfo(NotificationManagerActivity.this, "전화걸기", "전화 걸 시간입니다.", pendingIntent);
  notification.flags = Notification.FLAG_AUTO_CANCEL;
  notiMgr.notify(0, notification);
 }

 
}

 

 

 

 

// notification.xml

 

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="통지하기" />

</LinearLayout>

결과화면

 

// CustomToastDemo.java

 

package com.example.hellow;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

public class CustomToastDemo extends Activity{
 LinearLayout linear;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.custom_toast);

  Button show = (Button)findViewById(R.id.showToast);
  
  show.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    //레이아웃 파일을 읽어서 메모리에 인스턴스를 트리구조로 전개
    LinearLayout layout = (LinearLayout)getLayoutInflater().inflate(R.layout.toast1, null);
    Toast toast = Toast.makeText(CustomToastDemo.this, "Toast!!!", Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
   }
  });
 }
}

 

 

 

 

//  custom_toast.xml

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/showToast"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Custom_Toast" />

</LinearLayout>

 

 

--------------------------------------------------------------------------------------------------

 

//  toast1.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
   
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Custon_Toast(Top, 0, 10)"
        android:layout_gravity="bottom" />

</LinearLayout>

결과화면

 

txt파일 경로

 

 

 

// AssetDemo.java

 

 package com.example.hellow;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AssetDemo extends Activity{
 LinearLayout linear;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.asset_demo);

  try{
   InputStream is = getAssets().open("read_asset.txt");
   int size = is.available();
   
   byte[] buffer = new byte[size];
   is.read(buffer);
   is.close();
   
   String text = new String(buffer);
   linear = (LinearLayout)findViewById(R.id.linear);
   TextView tv = new TextView(this);
   tv.setText(text);
   tv.setTextSize(15.0f);
   linear.addView(tv);
  }catch(IOException e){
   Log.e("AssetDemo", "read file from Asset", e);
  }
 }
}


 

 

//  asset_demo.xml

 

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/linear">


</LinearLayout>

+ Recent posts