android - 在 android 中,我的 facebook url 必须加载到 xml 页面中,而不是进入浏览器

标签 android xml facebook facebook-graph-api

我是这个 android 的新手,我已经编写了在我的 android 应用程序中使用 facebook 的代码。

为了使用 facebook,我选择了一个苹果水果沙拉的 url

https://www.facebook.com/applefruitsalads

我可以访问 android 应用程序中的链接,但它必须在 xml 页面中打开,而不是转到浏览器然后加载上述 URL。

我不希望我的应用程序在浏览器中加载它,否则我需要它在 xml 文件中。

还有一件事我在 xml 页面中使用了 webview,这样它将填充给定到 webview 的 url

我不知道该怎么做所以任何人都可以帮助我。我已经粘贴了下面的代码

enter image description here

fbview.xml

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fb_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

FbActivity.java

package com.coded.sandeep;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;

@SuppressLint("SetJavaScriptEnabled")
public class FbActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView webView = (WebView) findViewById(R.id.fb_view);
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    webView.loadUrl("https://www.facebook.com/applefruitsalads");
       // i dont want to direct to browser instead it has to pop up in xml file only

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.facebook, menu);
    return true;
}}

我也在 list 文件中添加了语句 enter image description here

最佳答案

package com.coded.sandeep;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class FbActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView mWebview = (WebView) findViewById(R.id.fb_view);
    mWebview = (WebView) findViewById(R.id.webView1);
    WebSettings settings = mWebview.getSettings();
    settings.setJavaScriptEnabled(true);
    mWebview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    progressBar = ProgressDialog.show(FbActivity.this, "", "Loading...",
            true);
    mWebview.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        public void onPageFinished(WebView view, String url) {
            if (progressBar.isShowing()) {
                progressBar.dismiss();
            }
        }

        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            AlertDialog alert = new AlertDialog.Builder(FbActivity.this)
                    .create();
            alert.setTitle("No connection"));
            alert.setIcon(R.drawable.ic_launcher);
            alert.setCancelable(false);
            alert.setMessage("No connection"));
            alert.setButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                }
            });
            alert.show();
        }
    });
    mWebview.loadUrl("https://www.facebook.com/applefruitsalads");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.facebook, menu);
    return true;
}}

不要忘记在 Manifest 中添加 Internet Permission

我希望这能奏效

关于android - 在 android 中,我的 facebook url 必须加载到 xml 页面中,而不是进入浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22651995/

相关文章:

java - 如何显示其他用户的通知?

javascript - 来自 ajax 表单的 XML 请求

php - 使用 PHP 将 facebook 个人资料图片添加到高分表

java - 使用JSP在服务器上上传多个文件

ios - FBSDKLoginManager logInWithReadPermissions?

android - 如何指示 Gradle 从不同位置使用 Java?

java - 为什么我在没有使用 android.os.CountDownTimer 调用 Looper.prepare() 的线程中得到一个 "Can' t 创建处理程序?

android - 如何测量服务器的请求和响应时间?

excel - 将 Excelsheet 行转换为单独的 XML 文件时出现运行时错误

java - 在java中使用vtd-xml获取xml中的属性文本