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 no开发者_如何学Pythont able to find any info searching google.
Thanks, Jonah
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.
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" />
Just make a single Activity that hosts a single WebView and preload it with your url. Google it...it's mad easy
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.
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");
}
}
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)
精彩评论