2016-09-18 30 views
0

まず、AndroidとJavaの開発については、私は完全にnoobだと言いたいと思いますが、私は次のコードを実行して、甘い。WebViewのFacebookログイン後に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でのログイン後に空白のWebページが表示されてしまうだけだ。

これを解決する方法はありますか?すべてのヘルプは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"); 

こんにちは私は同じ問題を抱えていると私はsolved.Thisが原因あなたのactivity.Mayは、あなたが重いイメージを持ついくつかの背景を使用することロードに起こったこの

+0

こんにちは芽に関連のFacebookからデータをフェッチすることは非常に容易であるFacebookのSDKを使用してみてください@mansur ..私はちょうどあなたが私にあなたのコードを追加することができます。..全体のコードを書かれている..私あなたのコードを貼り付ける場所はわかりません。( – Mensur

+0

あなたのアンドロイドアプリでwebview経由でfacebook.comをロードしたいのですか?またはあなたのアプリを通じてFacebookのログインを実装したいのですか? – Moulesh

+0

アンドロイドアプリを介してウェブサイト...私のウェブサイトでは、私はフェイスブックアプリケーションを介して自分のウェブサイトにログインするためのボタンを実装しています..基本的に私は同じWebページを開くことができますwebrowser .. Webrowserと素晴らしい作品が、アンドロイドアプリは空白です。 – Mensur

0

を試してみてください。

おかげで、これはあなたを助けることを願っています

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

白い画面活動することをマニフェストファイルにこのテーマを追加し、この方法を試してみてください。

0

ログインして、そのユーザー

関連する問題