웹스쿨

웹뷰 작업시작 본문

개인 프로젝트/랜덤 이성 채팅

웹뷰 작업시작

마스터욱 2023. 3. 29. 00:43
반응형

 

 

 

 

헤헤 "랜덤 이성 채팅" 그럴싸한가?

아이콘이 기본이라서 좀 없어 보이긴 하지만... 아이콘은 이걸 쓸 예정이다.

어디서 많이 본거 같다... 그렇다... 어디서 많이 본거에서 색깔만 바꿨다... 나 지급 급해...

 

아래소스는 웹뷰에서 뒤로가기, 파일업로드 까지 되도록 모두 구현된 것이다.

 

MainActivity.java

 

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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.example.wook.myapplication;
 
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
 
public class MainActivity extends AppCompatActivity {
 
    private static final int FILECHOOSER_RESULTCODE   = 1;
    private final static int FILECHOOSER_LOLLIPOP_REQ_CODE = 2;
    private ValueCallback<Uri> mUploadMessage = null;
    private ValueCallback<Uri[]> filePathCallbackLollipop;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//타이틀바 없애기
//requestWindowFeature(Window.FEATURE_NO_TITLE); //setTheme(android.R.style.Theme_NoTitleBar_Fullscreen);

        setContentView(R.layout.activity_main);
        WebView WebView01 = (WebView) findViewById(R.id.webView01);
 
        WebView01.setWebChromeClient(new WebChromeClient(){
            // For Android 3.0-
            @SuppressWarnings("unused")
            public void openFileChooser(ValueCallback<Uri> uploadMsg) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                //i.setType("image/*");
                i.setType("*/*");
                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
            }
 
            // For Android 3.0+
            @SuppressWarnings("unused")
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);
            }
 
            // For Android 4.1+
            @SuppressWarnings("unused")
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                //i.setType("image/*");
                i.setType("*/*");
                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
            }
 
            // For Android 5.0+
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                                             WebChromeClient.FileChooserParams fileChooserParams) {
                Log.d("MainActivity""5.0+");
                if (filePathCallbackLollipop != null) {
                    filePathCallbackLollipop.onReceiveValue(null);
                    filePathCallbackLollipop = null;
                }
                filePathCallbackLollipop = filePathCallback;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("image/*");
                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_LOLLIPOP_REQ_CODE);
 
                return true;
            }
        });
 
 
 
        WebView01.setWebViewClient(new WebViewClient());
 
        WebSettings webSettings = WebView01.getSettings();
        webSettings.setJavaScriptEnabled(true);
 
        WebView01.loadUrl("http://story84.com/art/chating");
    }
 
//파일첨부
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == FILECHOOSER_RESULTCODE) {
            if (null == mUploadMessage)
                return;
            Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
            mUploadMessage.onReceiveValue(result);
            mUploadMessage = null;
        } else if (requestCode == FILECHOOSER_LOLLIPOP_REQ_CODE) {
            if (filePathCallbackLollipop == nullreturn ;
            filePathCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
            filePathCallbackLollipop = null;
        }
    }

public class BackPressCloseHandler { private long backKeyPressedTime = 0; private Toast toast; private Activity activity; public BackPressCloseHandler(Activity context) { this.activity = context; } public void onBackPressed() { if (System.currentTimeMillis() > backKeyPressedTime + 2000) { backKeyPressedTime = System.currentTimeMillis(); showGuide(); return; } if (System.currentTimeMillis() <= backKeyPressedTime + 2000) { activity.finish(); toast.cancel(); } } public void showGuide() { toast = Toast.makeText(activity, "뒤로 버튼을 한번 더 누르시면 종료됩니다.", Toast.LENGTH_SHORT); toast.show(); } } //뒤로가기 기능 BackPressCloseHandler backPressCloseHandler = new BackPressCloseHandler(this); @Override public void onBackPressed() { WebView WebView01 = (WebView) findViewById(R.id.webView01); //Log.d("wook", WebView01.getOriginalUrl()) if (WebView01.getOriginalUrl().equalsIgnoreCase(WebUrl)) { backPressCloseHandler.onBackPressed(); }else if(WebView01.canGoBack()){ WebView01.goBack(); }else{ backPressCloseHandler.onBackPressed(); } }
}
 
cs


 

manifasts >  AndroidManifast.xml

퍼미션 두줄 추가~

  1. <?xml version="1.0" encoding="utf-8"?>
  2.    package="com.jai.wook.jai">
  3.  
  4.     <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  5.     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
  6.  
  7.  
  8.     <application
  9.        android:allowBackup="true"
  10.        android:icon="@mipmap/ic_launcher"
  11.        android:label="@string/app_name"
  12.        android:roundIcon="@mipmap/ic_launcher_round"
  13.        android:supportsRtl="true"
  14.        android:theme="@style/AppTheme">
  15.         <activity android:name=".MainActivity">
  16.             <intent-filter>
  17.                 <action android:name="android.intent.action.MAIN" />
  18.  
  19.                 <category android:name="android.intent.category.LAUNCHER" />
  20.             </intent-filter>
  21.         </activity>
  22.     </application>
  23.  
  24. </manifest>

 

 

res > layout > Activity_main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. tools:context=".MainActivity">
  6.  
  7. <WebView
  8.    android:layout_width="match_parent"
  9.    android:layout_height="match_parent"
  10.    android:id="@+id/webView01"
  11.    >
  12.  
  13.  
  14. </WebView>
  15.  
  16. </LinearLayout>

 

 

res > values > styles.xml

 

  1. <resources>
  2.  
  3.     <!-- Base application theme. -->
  4.     <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  5.         <!-- Customize your theme here. -->
  6.         <item name="colorPrimary">@color/colorPrimary</item>
  7.         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  8.         <item name="colorAccent">@color/colorAccent</item>
  9.  
  10.         <item name="windowActionBar">false</item>
  11.         <item name="windowNoTitle">true</item>
  12.     </style>
  13.  
  14. </resources>
  15.  

이 게시글은
https://webschool.kr/?v=board_view&board_key=9&idx=69
에서 작성한 글입니다. 소스코드의 경우 해당 블로그에서 이뿌게 노출이 되지 않을 수 있사오니, 위 링크로 들어오셔서 보시길 바랍니다.

반응형

'개인 프로젝트 > 랜덤 이성 채팅' 카테고리의 다른 글

플레이 스토어에 등록완료  (0) 2023.03.29
apk 배포 ㄱㄱ  (0) 2023.03.29
게시판 개발  (0) 2023.03.29
사진 첨부까지 완료  (0) 2023.03.29
대화 프로그램 개발  (0) 2023.03.29