1
Android Webview 앱을 만들고 정상적으로 작동하지만 사진을 업로드하는 데 사용되는 버튼을 누르면 아무런 변화가 없습니다. 너희들이Android Webview 앱, 업로드 이미지가 작동하지 않음, 사진 선택을 탭하면 아무런 변화가 없습니다.
MainActivity.java
public class MainActivity extends AppCompatActivity {
private WebView myWebView;
private ValueCallback<Uri> mUploadMessage;
private final static int FILECHOOSER_RESULTCODE = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
myWebView = new WebView(this);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
myWebView.setWebChromeClient(new WebChromeClient() {
//The undocumented magic method override
//Eclipse will swear at you if you try to put @Override here
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
MainActivity.this.showAttachmentDialog(uploadMsg);
}
// For Android > 3.x
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
MainActivity.this.showAttachmentDialog(uploadMsg);
}
// For Android > 4.1
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
MainActivity.this.showAttachmentDialog(uploadMsg);
}
});
this.setContentView(myWebView);
myWebView.loadUrl("http://www.droidocial.com");
}
private void showAttachmentDialog(ValueCallback<Uri> uploadMsg) {
this.mUploadMessage = uploadMsg;
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*");
this.startActivityForResult(Intent.createChooser(i, "Choose type of attachment"), FILECHOOSER_RESULTCODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == FILECHOOSER_RESULTCODE) {
if (null == this.mUploadMessage) {
return;
}
Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData();
this.mUploadMessage.onReceiveValue(result);
this.mUploadMessage = null;
}
}
@Override
public void onBackPressed() {
if (myWebView.canGoBack()) {
myWebView.goBack();
} else {
super.onBackPressed();
}
}
의 AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="com.official.droidocial.droidocial.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
날 도울 수 있도록 내 코드를 부착 해요
너무 많이 시도했지만 여전히이 오류에 빠져 있습니다. 누군가이 오류를 해결할 수있는 방법을 말해 줄 수 있습니까?
내가 mainactivity에이를 넣어 샤 우드 :
또한 당신은 장치의 파일에 액세스하기 위해이 권한이 필요합니까? – Syndicate@Syndicate 위의 코드는 onAcitivtyResult에 있어야합니다. – j2ko
고마워요 @ j2ko, 그 지금 일하고있어 (Y) – Syndicate