【发布时间】:2014-01-15 23:15:52
【问题描述】:
我已经创建了一个使用 WebView 来查看我的网站的应用程序,该应用程序运行顺利并且没有任何错误,我什至将它上传到了 Google Play 商店。唯一的问题是我的网站中有 youtube 视频链接,但它们在我的应用程序中不起作用。它们出现在屏幕上,用户可以轻松地点击它们,但在点击视频加载标志后会出现并保持旋转而没有任何好处。我知道移动网络浏览器没有 Flash 播放器插件,我在 StakcOverFlow 上查看了所有类似的问题。所以我想做的是让我的应用程序从android系统调用YouTube应用程序,让它通过播放我的网站youtube视频来完成任务。我阅读了有关 Intent 方法的信息,但找不到任何有用的信息。有什么建议吗?
谢谢你svenoaks。现在我在代码中有一个小错误:
package com.parse;
import android.net.Uri;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class ParserActivity extends Activity {
private WebView myWebView;
@SuppressLint({"setJavaScriptEnabled"})
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_parser);
myWebView =(WebView) findViewById(R.id.webview);
myWebView.loadUrl("https://parse.com/apps/aramco-app1/push_notifications /new");
myWebView.setWebViewClient(new HelloWebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
myWebView.setScrollbarFadingEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.getSettings().setSupportZoom(true);
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{webview.loadUrl (url);
return true;
{
// YouTube video link
if (url.startsWith("vnd.youtube:"))
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse
(String.format("http://www.youtube.com/v/%s", url.substring("vnd.youtube:".length())))));
return true;
}
return false;
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
Toast.makeText(WebActivity.this, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack())
{
myWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
public boolean setIsZoomInEnabled;
}
class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
private void show()
{
// TODO: Implement this method
}
}
onReceive 方法有一个错误。
【问题讨论】:
标签: android eclipse webview youtube