2016-09-18 133 views
0

首先,我想说的是,当我涉及到Android和Java开发时,我总是noob,但我已经设法运行下面的代码,它激活了我的网站。甜。Facebook上登录WebView后的Android应用程序空白屏幕

下面是代码:

package se.madesolutions.cmok; 

import android.net.Uri; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.webkit.WebSettings; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

import com.google.android.gms.appindexing.Action; 
import com.google.android.gms.appindexing.AppIndex; 
import com.google.android.gms.common.api.GoogleApiClient; 

public class MainActivity extends AppCompatActivity { 

/** 
* ATTENTION: This was auto-generated to implement the App Indexing API. 
* See https://g.co/AppIndexing/AndroidStudio for more information. 
*/ 
private GoogleApiClient client; 
private WebView mywebView; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    mywebView = (WebView)findViewById(R.id.webView); 
    WebSettings webSettings = mywebView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    mywebView.loadUrl("http://mywebsite.com"); 

    mywebView.setWebViewClient(new WebViewClient()); 


    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    //setSupportActionBar(toolbar); 

    // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
} 

@Override 
public void onBackPressed() { 
    if(mywebView.canGoBack()){ 
     mywebView.goBack(); 
    } else { 
     super.onBackPressed(); 
    } 

} 

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

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    //noinspection SimplifiableIfStatement 
    if (id == R.id.action_settings) { 
     return true; 
    } 

    return super.onOptionsItemSelected(item); 
} 

@Override 
public void onStart() { 
    super.onStart(); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client.connect(); 
    Action viewAction = Action.newAction(
      Action.TYPE_VIEW, // TODO: choose an action type. 
      "Main Page", // TODO: Define a title for the content shown. 
      // TODO: If you have web page content that matches this app activity's content, 
      // make sure this auto-generated web page URL is correct. 
      // Otherwise, set the URL to null. 
      Uri.parse("http://host/path"), 
      // TODO: Make sure this auto-generated app URL is correct. 
      Uri.parse("android-app://se.madesolutions.cmok/http/host/path") 
    ); 
    AppIndex.AppIndexApi.start(client, viewAction); 
} 

@Override 
public void onStop() { 
    super.onStop(); 

    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    Action viewAction = Action.newAction(
      Action.TYPE_VIEW, // TODO: choose an action type. 
      "Main Page", // TODO: Define a title for the content shown. 
      // TODO: If you have web page content that matches this app activity's content, 
      // make sure this auto-generated web page URL is correct. 
      // Otherwise, set the URL to null. 
      Uri.parse("http://host/path"), 
      // TODO: Make sure this auto-generated app URL is correct. 
      Uri.parse("android-app://se.madesolutions.cmok/http/host/path") 
    ); 
    AppIndex.AppIndexApi.end(client, viewAction); 
    client.disconnect(); 
} 
} 

我所做的是,我已经实现了我的网站上,用户可以轻松登陆Facebook登录。这在我在台式计算机上测试时效果很好,但当试图通过启动相同网站的Android应用程序登录时,我只是在用Facebook登录后才得到空白网页。

有没有人有任何想法如何解决这个问题?所有帮助appriciated。

回答

0
mywebView.setWebViewClient(new WebViewClient(){ 
      @Override 
      public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
       Toast.makeText(getContext(), description, Toast.LENGTH_SHORT).show(); 
      } 

      @Override 
      public void onPageFinished(WebView view, String url) { 
       super.onPageFinished(view, url); 
       progressBar.setVisibility(View.GONE); 
      } 
     }); 
     mywebView.loadUrl("http://mywebsite.com"); 

尝试这个

+0

芽嗨Facebook的数据..我刚才writen整个代码..你可以添加你的代码放到我的..我不知道在哪里粘贴你的代码..对不起,队友总noob在这里:( – Mensur

+0

你只是想通过在你的Android应用程序的webview加载facebook.com ??或者你想通过你的应用程序实现Facebook登录? – Moulesh

+0

没有即时加载我的网站通过Android应用程序...在我的网站上,我已经实现了一个按钮,通过Facebook应用程序登录到我的网站..所以基本上,我可以通过webrowser打开相同的网页..登录与webrowser很好,但是当我测试相同的登录android应用程序只是空白。 – Mensur

0

您好我有同样的问题,我有solved.This发生因加载你的activity.May是你用了一些背景重图像。

尝试这种方式

添加这个主题在你的清单文件白屏活动

android:theme="@android:style/Theme.Translucent.NoTitleBar" 

感谢希望这会帮助你。

0

@mansur尝试使用Facebook的SDK,这是非常容易的登录并获取从该用户相关的

相关问题