안녕하세요.
이번에 어플을 테스트하며 개발을 해보고있는 학생입니다.
오류가 발생하는것도 아니고 결제모듈이 뜨기전까지는 또 백키가 먹히나 결제모듈을 불러오면 백키가 먹히질 않습니다.
webview에서 백키를 구현하는 부분에 로그켓을 두고 봐도 백키는 입력이 되는데 제 성능을 내지 못하는거 같습니다.........
01.
super
.onCreate(savedInstanceState);
02.
setContentView(R.layout.main);
03.
mWebView = (WebView) findViewById(R.id.webview);
04.
String url =
"-------------------------------------------"
;
05.
String postData =
""
;
06.
mWebView.postUrl(
"url ,EncodingUtils.getBytes(postData, "
BASE64"));
07.
mWebView.getSettings().setJavaScriptEnabled(
true
);
08.
mWebView.setWebViewClient(
new
CustomScheme());
09.
mWebView.setWebChromeClient(
new
WebChromeClient(){
10.
@Override
11.
public boolean onJsAlert(WebView view, String url, String message, final JsResult result){
12.
new
AlertDialog.Builder(GalleryExample.
this
)
13.
.setTitle(
"경고"
)
14.
.setMessage(message)
15.
.setPositiveButton(android.R.string.ok,
16.
new
AlertDialog.OnClickListener(){
17.
public void onClick(DialogInterface dialog, int which){
18.
result.confirm();
19.
}
20.
})
21.
.setCancelable(
false
)
22.
.create()
23.
.
show
();
24.
return
true
;
25.
}
26.
});
27.
}
28.
@Override
29.
public boolean onKeyDown(int keyCode, KeyEvent event) {
30.
if
((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
31.
mWebView.goBack();
32.
return
true
;
33.
}
34.
return
super
.onKeyDown(keyCode, event);
35.
}
36.
37.
private class CustomScheme extends WebViewClient {
38.
@Override
39.
public boolean shouldOverrideUrlLoading(WebView view, String url) {
40.
if
(url.endsWith(
".apk"
)){
41.
downloadFile(url);
42.
return
super
.shouldOverrideUrlLoading(view, url);
43.
}
else
if
(url.startsWith(
"http:"
) || url.startsWith(
"https:"
)) {
44.
view.loadUrl("url);
45.
}
else
{
46.
Uri uri = Uri.parse(url);
47.
Intent intent =
new
Intent(Intent.ACTION_VIEW, uri);
48.
try
{
49.
startActivity(intent);
50.
}
catch
(ActivityNotFoundException ex) {
51.
return
false
;
52.
}
53.
}
54.
return
true
;
55.
}
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
private void downloadFile(String fileUrl){
70.
URL myFileUrl =
null
;
71.
try
{
72.
myFileUrl=
new
URL("fileUrl);
73.
}
catch
(MalformedURLException e) {
74.
e.printStackTrace();
75.
}
76.
try
{
77.
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
78.
conn.setDoInput(
true
);
79.
conn.connect();
80.
InputStream
is
= conn.getInputStream();
01.
02.
String mPath =
"sdcard/v3mobile.apk"
;
03.
FileOutputStream fos;
04.
File f =
new
File(mPath);
05.
if
( f.createNewFile() ) {
06.
fos =
new
FileOutputStream(mPath);
07.
int read;
08.
while
( (read =
is
.read()) != -1) {
09.
fos.write(read);
10.
}
11.
fos.close();
12.
}
13.
}
catch
(IOException e) {
14.
e.printStackTrace();
15.
}
16.
Toast.makeText(getApplicationContext(),
"download complete"
, 0).
show
();
17.
18.
19.
File apkFile =
new
File(Environment.getExternalStorageDirectory()+
"/v3mobile.apk"
);
20.
Intent intent =
new
Intent(Intent.ACTION_VIEW);
21.
intent.setDataAndType( Uri.fromFile(apkFile),
"application/vnd.android.package-archive"
);
22.
startActivity(intent);
23.
}
24.
}
25.
}
그경우 아래 소스를 넣어주시면 잘됩니다. WebViewClient 클래스에
추가해주시면 잘됩니다.