在 Web 视图中显示.swf文件



有人可以帮我把.swf文件显示到 WebView 中吗,我试图这样做,但它显示的是白色窗口而不是 WebView。我也试图显示一个简单的网站,它也显示了一个空窗口。

片段.java

package com.app.clupascu.oavm;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class FirstFragment extends Fragment {

@SuppressLint("SetJavaScriptEnabled")
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_first, container, false);
String url ="file:///android_asset/map.swf";
WebView mWebView=(WebView) v.findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.loadUrl(url);
return inflater.inflate(R.layout.fragment_first, container, false);
}
}

在这里,我尝试将.swf文件加载到WebView中。 我认为问题出在这个文件中,我试图加载一个简单的网站,但也没有结果。

片段.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />
</RelativeLayout>

主页.java

package com.app.clupascu.oavm;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
public class MainPage extends AppCompatActivity {

private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_home:
setTitle("Map");
FirstFragment fragment = new FirstFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment);
fragmentTransaction.commit();
return true;
case R.id.navigation_dashboard:
setTitle("History");
SecondFragment fragment2 = new SecondFragment();
FragmentTransaction fragmentTransaction2 = getSupportFragmentManager().beginTransaction();
fragmentTransaction2.replace(R.id.fram, fragment2);
fragmentTransaction2.commit();
return true;
case R.id.navigation_notifications:
setTitle("Schedule");
ThirdFragment fragment3 = new ThirdFragment();
FragmentTransaction fragmentTransaction3 = getSupportFragmentManager().beginTransaction();
fragmentTransaction3.replace(R.id.fram, fragment3);
fragmentTransaction3.commit();
return true;
}
return false;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
setTitle("Map");
FirstFragment fragment = new FirstFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fram, fragment);
fragmentTransaction.commit();
}
}

谢谢!

SWF 是一个 ShockWaveFlash 文件。Web浏览器无法在没有Flash插件帮助的情况下运行/显示ShockWave Flash文件。

Android的Flash插件已经在几年前停产了。因此,您将无法成功使其在 Web 视图中运行。

因此,您必须重新考虑您的应用程序设计以及如何在没有该 SWF 文件的情况下实现您想要的原因。

无论如何,使用将在 2 年内(2020 年底(达到生命周期结束的技术启动新应用程序不是一个好主意。

最新更新