2016-11-10 42 views
-4

我的博客是www.efficientprogrammer.com。我打算爲我的博客構建一個Android應用程序。我的博客由Blogger提供支持。我想構建一個本地應用程序(我想從頭開始爲我的應用程序編寫代碼)。我對Android有基本的知識,所以我很樂於編寫代碼。將博客或網站轉換爲Android應用程序

是否有任何API可用於連接android應用程序和博主? 如果是的話,那麼請給我一些資源,我可以找到他們。

請給我幾個想法,這將使我的工作變得簡單。

預先感謝您!

回答

1

如果您只需將現有的博客網站連接到android應用程序,那麼您可以使用WebView。

內聯是會做你的工作的類。只需輸入你想要的網址即可。

import android.content.Intent; 
import android.graphics.Bitmap; 
import android.os.Bundle; 
import android.support.v4.content.ContextCompat; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.view.View; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import com.kspl.smarthelmet.R; 

public class AppWebView extends AppCompatActivity { 

    WebView webView; 
    String url; 
    String title; 
    Toolbar toolbar; 
    String uri; 

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

     /** 
     * Use this bundle value to set Title and URL for WebView ... 
     */ 
     Bundle b = getIntent().getExtras(); 
     url = b.getString("url"); 
     title = b.getString("title"); 

     //regular = Typeface.createFromAsset(getAssets(), "opensans-regular.ttf"); 

     toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     toolbar.setNavigationIcon(R.drawable.cross); 

     getSupportActionBar().setTitle(title); 
     toolbar.setTitleTextColor(ContextCompat.getColor(this, R.color.secondary_text)); 
     toolbar.setNavigationOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       finish(); 
      } 
     }); 

     webView = (WebView)findViewById(R.id.tnc_web); 
     webView.getSettings().setJavaScriptEnabled(true); 
     webView.setWebViewClient(new myWebClient()); 
     webView.loadUrl(url); 

    } 



    public class myWebClient extends WebViewClient 
    { 
     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon) { 
      super.onPageStarted(view, url, favicon); 
     } 

     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      if (url.startsWith("mailto:")) { 
       String[] blah_email = url.split(":"); 
       Intent emailIntent = new Intent(Intent.ACTION_SEND); 
       emailIntent.setType("text/plain"); 
       emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{blah_email[1]}); 
       startActivity(emailIntent); 
      } 
      else if (url.startsWith("tel:")) { 
       uri = url; 
       /*Intent intent = new Intent(Intent.ACTION_CALL); 
       intent.setData(Uri.parse(uri)); 
       startActivity(intent);*/ 
      } 
      else if (url.endsWith("error.jsp")) { System.out.println("==== Some error occured ====="); } 

      else 
      { 
       view.loadUrl(url); 
       //progressBar.setVisibility(View.VISIBLE); 
      } 
      return true; 

     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      super.onPageFinished(view, url); 

      //UiUtil.dismissProgressDialog(); 
     } 

    } 

} // End of main class over here ... 

和XML部分

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.kspl.smarthelmet.activity.AppWebView" 
    tools:showIn="@layout/activity_app_web_view"> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="2dp" 
     android:background="@color/secondary_text" 
     android:id="@+id/view" 
     ></View> 

    <WebView 
     android:layout_below="@+id/view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/tnc_web" 
     ></WebView> 

</RelativeLayout> 

現在,如果你希望不希望您的網址鏈接到Android應用程序,並希望使自己的博客應用程序,那麼你將被要求思考和一方面設計應用程序。其次,您需要一臺服務器來託管API。 然後,您將將該API鏈接到您決定的設計。

0

1最簡單的方法是使用一個響應主題爲您的網站和Android Studio中創建一個應用程序有一個的WebView

2-硬&更好的方法是爲你的網站創建問題的REST阿比服務,並通過HTTP請求連接到Android應用程序。爲此,您可以使用改裝Volley庫。

希望得到這個幫助

相關問題