Jonah
Jonah

Reputation: 16202

Create Android App That Acts As A Shortcut To Our Mobile Site

We have a special mobile version of our site that we would like to promote in the android marketplace. The "app" would effectively be a shortcut to the website, but you would be able to download it and have an icon for it, just like any other app.

Is this possible? If so, can you link me to instructions? I was not able to find any info searching google.

Thanks, Jonah

Upvotes: 11

Views: 11891

Answers (6)

Simoné Sego
Simoné Sego

Reputation: 11

Just make a single Activity that hosts a single WebView and preload it with your URL it's really easy.

I have a similar App and did this.

Upvotes: 1

BayK
BayK

Reputation: 118

I have similar App. It has a webview and it shows progress while your site is loading.

There are two classes WebViewProgress.java Resources - it is easy to figure out. This code works well.

package com.promo.drr;

import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class WebViewProgress extends WebViewClient {
    private ProgressBar progressBar;

    public WebViewProgress(ProgressBar progressBar) {
        this.progressBar=progressBar;
        progressBar.setVisibility(View.VISIBLE);
    }
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        progressBar.setVisibility(View.GONE);
    }
}

App.java

package CCCC;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.webkit.WebView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;

public class App extends AppCompatActivity {

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

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;
        int progressSz = Math.min(height,width) / 4;
        int marginX = (width-progressSz)/2;
        int marginY = (height-progressSz)/2;

        ProgressBar progress = (ProgressBar)findViewById(R.id.progressBar);
        RelativeLayout.LayoutParams margineParam =  (RelativeLayout.LayoutParams) progress.getLayoutParams();
        margineParam.setMargins(marginX, marginY,marginX,marginY);
        progress.setLayoutParams(margineParam);

        WebView wv = (WebView) findViewById( R.id.webview);
        wv.getSettings().setJavaScriptEnabled(true);
        wv.setWebViewClient(new WebViewProgress( progress) );
        wv.loadUrl("https://your site url");

    }
}

image

Upvotes: 0

NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.

"<Intent>" does not set the required layout_width attribute:
 (1) Set to "wrap_content"
 (2) Set to "match_parent"
"<Intent>" does not set the required layout_height attribute:
 (1) Set to "wrap_content"
 (2) Set to "match_parent"
You must supply a layout_width attribute.
You must supply a layout_height attribute.

The following classes could not be found:

- Intent (Fix Build Path, Edit XML)

Upvotes: -3

yogsma
yogsma

Reputation: 10586

  Uri uri = Uri.parse("http://www.example.com");
 Intent intent = new Intent(Intent.ACTION_VIEW, uri);
 startActivity(intent);

Add to your androidManifest.xml file ..below line

<uses-permission android:name="android.permission.INTERNET" />

Upvotes: 3

Rich
Rich

Reputation: 36806

Just make a single Activity that hosts a single WebView and preload it with your url. Google it...it's mad easy

Upvotes: 1

Nick Campion
Nick Campion

Reputation: 10479

This is possible and fairly easy.

Your application would be a single Activity. That activity would create a new intent based on the info here on the google intents. The intent would be of type VIEW_ACTION and you'd give it an url as a value. Then you'd simply do:

onCreate(Bundle bundle){
 Intent myIntent = new Intent(Intent.VIEW_ACTION, Uri.parse("http://www.google.com"));
 startActivity(myIntent); 
}

The rest of the exercise is just wrapping that with the AndroidManifest.xml and putting it into the market.

The alternative would be to provide a webview, but, thats pretty pointless if your website is designed to function in a mobile browser already.

Upvotes: 10

Related Questions