Do you want to convert your Website/ Blog into Android Application?
Are you a Beginner to Android Application Development?
If above question's answer is yes then go through this article because this article is just for the beginners.
So let's start how you can create your First Android Application in Android Studio.
If you have any queries related to this tutorial then you can comment below....
I hope you like this tutorial on building your first android application for your website. If so, then share this tutorial using sharing buttons below....
Are you a Beginner to Android Application Development?
If above question's answer is yes then go through this article because this article is just for the beginners.
So let's start how you can create your First Android Application in Android Studio.
- First of all, Start a new Project.
- Now Enter your Application Name, Domain Name and click on Next.
- Then choose platform Phone & Tablet as you going to make Android Application for Mobile.
- Now select any one of the Activity.(Here I'm choosing Google AdMob Ads Activity) and click on Finish.
- On the next step, you will get two files MainActivity.java and activity_main.xml
- In the activity_main.xml file, go to Design tab and delete "Hello World".
- Now select Containers and Drag & Drop the WebView to your application.
- Then Go to text tab of activity_main.xml and add this one line inside WebView.
android:id="@+id/activity_main_webview"
- after adding the code will be like
<WebViewandroid:id="@+id/activity_main_webview"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentTop="true"android:layout_alignParentStart="true"android:layout_above="@+id/adView" />
- Now you need to add some lines of code to your MainActivity.java file.Go to MainActivity.java and add the below codes after setContentView(R.layout.activity_main); this line.
myWebView = (WebView) findViewById(R.id.activity_main_webview); WebViewClient webViewClient = new WebViewClient(); myWebView.setWebViewClient(webViewClient); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl("http://www.trickscloud.net");
- Now add these lines to the above of MainActivity.java file.
import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient;
- Then add one more line below public class MainActivity extends AppCompatActivity this line.
private WebView myWebView;
- The complete MainActivity.java code...
package net.trickscloud.trickscloud; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends AppCompatActivity { private WebView myWebView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myWebView = (WebView) findViewById(R.id.activity_main_webview); WebViewClient webViewClient = new WebViewClient(); myWebView.setWebViewClient(webViewClient); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl("http://www.trickscloud.net"); // Load an ad into the AdMob banner view. AdView adView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .setRequestAgent("android_studio:ad_template").build(); adView.loadAd(adRequest); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
- Now just you need to give internet permission to your Application. Go to AndroidManifest.xml and paste this one line...
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
- If you want to add your AdMob Ad Unit in your App then in activity_main.xml file enter your Ad Unit Id...
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />Congratulation! You have completed building your First Application in Android Studio.
If you have any queries related to this tutorial then you can comment below....
I hope you like this tutorial on building your first android application for your website. If so, then share this tutorial using sharing buttons below....
Nice post, am really sure it'll come me handy...Thanks for the update
ReplyDeleteVery nice... i really like your blog.
ReplyDelete
ReplyDeleteCarry on Don't Stop Posting.