一款彩票app的制作运营详解

编程入门 行业动态 更新时间:2024-10-10 05:16:33

(注:本文只介绍代码实现重点部分。)

app下载地址

前几日去买彩票,在选号码时很是苦恼,分析数据吧,咱不会,蒙吧,肯定没戏。想了一想,为什么不做一个生成彩票号码的app呢?好,说干就干。

-----------------------------------------

安卓开发自己已经有了一定的基础。屡一下思路,也就是界面+简单算法(生成对应的随机数序列就可以了)。先给app起个响亮的名字吧,恩。。就叫“小石彩票助手”。

第一大步:开发

在eclipse中新建工程Lottery(彩票)

接着设计下主界面布局


既然是彩票助手,所以体彩和福彩所有彩种都得支持。(查阅对应官网,找到每种彩票玩法,开奖号是由几个数字组成等等。)

为什么有个”打赏小石“按钮呢?这个你懂得,不多做解释。

我们在layout文件夹下建立对应的布局文件。这里我采用listview来显示这些按钮。而这个listview其实只有一个item。因为为了适应不同的手机屏幕,做成只有一个item的listview可以直接对按钮进行滑动操作。

主界面布局文件

<RelativeLayout xmlns:android="http://schemas.android/apk/res/android"
    xmlns:tools="http://schemas.android/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
         >
    </ListView>


</RelativeLayout>

接着在MainActivity中对listview进行适配器绑定等操作。

// 获取listview控件
		ListView lv1 = (ListView) findViewById(R.id.listView1);
		// 绑定适配器
		lv1.setAdapter(new MyAdapter(this));

/**
	 * ListView的适配器实现
	 * 
	 * @author MR.Stone
	 * 
	 */
	class MyAdapter extends BaseAdapter {
		LayoutInflater inflater;
		Context context;

		public MyAdapter(Context context) {
			this.context = context;
		}

		@Override
		public int getCount() {
			// 为了适应不同机型,才将开始液面作为只有一个item的listview
			return 1;
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			inflater = LayoutInflater.from(context);
			// 加载布局文件
			convertView = inflater.inflate(R.layout.listitem, null);
			init(convertView);
			return convertView;
		}

	}

listitem.xml文件内容

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/lanmubeijing"
        android:text="体彩" 
        android:textSize="22dp"
        android:layout_gravity="center_horizontal"/>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageButton
                android:id="@+id/bt_dlt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/daletou" />

            <ImageButton
                android:id="@+id/bt_qxc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/qixingcai" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageButton
                android:id="@+id/bt_pls"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/pailiesan" />

            <ImageButton
                android:id="@+id/bt_plw"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/pailiewu" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>
    </TableLayout>

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/lanmubeijing"
        android:text="福彩" 
        android:textSize="22dp"
        android:layout_gravity="center_horizontal"/>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <ImageButton
                android:id="@+id/bt_ssq"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/shuangseqiu" 
                android:layout_weight="1"/>

            <ImageButton
                android:id="@+id/bt_qlt"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/qilecai" 
                android:layout_weight="1"/>

            <ImageButton
                android:id="@+id/bt_3d"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/sandi" 
                android:layout_weight="1"/>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

        </TableRow>

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>

        <TableRow
            android:id="@+id/tableRow7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/bt_ds"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/lanmubeijing"
        android:text=">>打赏小石" 
        android:textSize="22dp"
        android:layout_gravity="center_horizontal"/>

</LinearLayout>

接着创建OpenActivity继承activity。这是我们的摇奖界面。


在主界面点击按钮跳转至摇奖界面用到的代码

/**
	 * 按钮点击相应事件
	 */
	@Override
	public void onClick(View v) {
		String kind = "";
		switch (v.getId()) {
		case R.id.bt_ds:
			Intent intent = new Intent();
			intent.setClass(MainActivity.this, AwardActivity.class);//打赏小石界面
			startActivity(intent);
			return;
		case R.id.bt_dlt:
			kind = "大乐透";
			break;
		case R.id.bt_qxc:
			kind = "七星彩";
			break;
		case R.id.bt_pls:
			kind = "排列三";
			break;
		case R.id.bt_plw:
			kind = "排列五";
			break;
		case R.id.bt_ssq:
			kind = "双色球";
			break;
		case R.id.bt_qlt:
			kind = "七乐彩";
			break;
		case R.id.bt_3d:
			kind = "3D";
			break;
		}
		Intent intent = new Intent();
		intent.putExtra("kind", kind);
		intent.setClass(MainActivity.this, OpenActivity.class);
		startActivity(intent);
	}

这个界面要实现的功能是通过摇一摇手机,生成对应的购彩号码。这时我们新建一个工具类Generate

package com.utils;

import java.util.LinkedList;
import java.util.Random;

import com.xiaoshi.lottery.R;

public class Generate {
	//根据彩票种类生成号码
	public static String getNum(String kind) {

		if (kind.equals("大乐透")) {
			//getResult生()成1-35中的5个数字
			return getResult(35, 5) + "+ " + getResult(12, 2);
		}
		if (kind.equals("七星彩")) {
			Random rand = new Random();
			String s = rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10);
			return s;

		}
		if (kind.equals("排列三")) {
			Random rand = new Random();
			String s = rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10);
			return s;

		}
		if (kind.equals("排列五")) {
			Random rand = new Random();
			String s = rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10) ;
			return s;
		}
		if (kind.equals("双色球")) {
			return getResult(33, 6) + "+ " + getResult(16, 1);
		}
		if (kind.equals("七乐彩")) {
			return getResult(30, 7);
		}
		if (kind.equals("3D")) {
			Random rand = new Random();
			String s = rand.nextInt(10) + " " + rand.nextInt(10) + " "
					+ rand.nextInt(10);
			return s;
		}
		return "发生错误";
	}

	public static int getKindId(String kind) {

		if (kind.equals("大乐透")) {

			return 1;
		}
		if (kind.equals("七星彩")) {
			
			return 1;

		}
		if (kind.equals("排列三")) {
			return 1;

		}
		if (kind.equals("排列五")) {
			return 1;
		}
		if (kind.equals("双色球")) {
			return 0;
		}
		if (kind.equals("七乐彩")) {
			return 0;
		}
		if (kind.equals("3D")) {
			return 0;
		}
		return 0;
	}
	
	static String getResult(int total, int nums) {
		// 用list来装载开奖号码
		LinkedList<Integer> listNum = new LinkedList<Integer>();
		for (int i = 0; i < total; i++) {
			listNum.add(i + 1);
		}
		// 用来生成随机数
		Random rand = new Random();
		String result = "";
		int k;
		for (int i = 0; i < nums; i++) {
			k = rand.nextInt(total);
			result += (listNum.get(k) > 9 ? (listNum.get(k) + "")
					: ("0" + listNum.get(k))) + " ";
			listNum.remove(k);
			total--;
		}

		return result;
	}
}

然后在OpenActivity实现摇一摇功能后调用getNum(kind)方法。

摇一摇实现功能

private void rock() {
		// 1获得硬件信息
		mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
		vibrator = (Vibrator) getSystemService(Service.VIBRATOR_SERVICE);
		activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

		// 2 判断当前手机是否带加速度感应器,如果不带,直接结束,不启动服务
		List<Sensor> sensors = mSensorManager
				.getSensorList(Sensor.TYPE_ACCELEROMETER);
		if (sensors != null)
			if (sensors.size() == 0)
				return;

		// 3生成感应侦听事件
		sensorelistener = new SensorEventListener() {
			@Override
			public void onAccuracyChanged(Sensor sensor, int accuracy) {
				// TODO Auto-generated method stub

			}

			// 感应器发生改变
			@Override
			public void onSensorChanged(SensorEvent event) {
				// TODO Auto-generated method stub
				int sensorType = event.sensor.getType();

				// 读取摇一摇敏感值
				int shakeSenseValue = 18;
				// values[0]:X轴,values[1]:Y轴,values[2]:Z轴
				float[] values = event.values;

				if (sensorType == Sensor.TYPE_ACCELEROMETER) {
					if ((Math.abs(values[0]) > shakeSenseValue
							|| Math.abs(values[1]) > shakeSenseValue || Math
							.abs(values[2]) > shakeSenseValue)) {
						// 触发事件,执行打开应用行为
						vibrator.vibrate(500);
						tvNum.setText(Generate.getNum(kind));

					}
				}
			}

		};

		// 4注册侦听事件
		mSensorManager.registerListener(sensorelistener,
				mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
				SensorManager.SENSOR_DELAY_NORMAL);

	}

这个界面中需要定义的成员变量

TextView tvKind;// 彩种文本
TextView tvChunyue;// 穿越文本
TextView tvNum;// 开奖号码
Button btn_web;// 查看开奖结果
Button btn_wx;// 分享好友
String kind;


再来就是需要查看开奖结果,这时我们新建WebResultActivity,点击按钮跳转到这个界面就可以了。其布局文件中用到一个WebView

package com.xiaoshi.lottery;

import com.xiaoshi.lottery.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;

public class WebResultActivity extends BaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		FullScreen();
		setContentView(R.layout.activity_web_result);
		int kindId = getIntent().getExtras().getInt("kind");
		WebView wv = (WebView) findViewById(R.id.webView1);
		// 设置WebView属性,能够执行Javascript脚本
		wv.getSettings().setJavaScriptEnabled(true);
		if (kindId == 1) {
			wv.loadUrl("http://www.lottery.gov/");
		} else {
			wv.loadUrl("http://www.cwl.gov/");
		}

	}

}

这时1.0版本基本成型了。

第二大步:推广

如果你对自己的app比较自信,或者是同时想捞点辛苦费,这时您就可以考虑怎么推广自己的app,怎么通过app赚外快了。

这里我用到的一个简单的推广办法就是微信推广,朋友给朋友介绍的软件安装率应该才高么。

首先在微信开放平台申请账号、注册登录->创建自己的应用->填写相关信息->待审核通过后->你就可以获得该app对应的appkey等信息了。

实现代码时首先在manifest中添加对应的权限(有些多余的是为了后期加广告)

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" >
    </uses-permission>
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.GET_TASKS" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />

然后在自己的工程中新建包    自己程序包名+wxapi ,在此包下新建类WXEntryActivity,名字必须是这个。导入对应jar包,WXEntryActivity内容

package com.xiaoshi.lottery.wxapi;


import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
	private IWXAPI api;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		api = WXAPIFactory.createWXAPI(this, "wx****************caa", false);//第二个参数到时填自己的appkey
		api.handleIntent(getIntent(), this);
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onResp(BaseResp resp) {
		// LogManager.show("TAG", resp.errCode: + resp.errCode + ,resp.errStr: +
		// resp.errStr, 1);
		switch (resp.errCode) {
		case BaseResp.ErrCode.ERR_OK:
			// 分享成功
			Log.e("test", "成功");
			break;
		case BaseResp.ErrCode.ERR_USER_CANCEL:
			// 分享取消
			Log.e("test", "取消");
			break;
		case BaseResp.ErrCode.ERR_AUTH_DENIED:
			// 分享拒绝
			Log.e("test", "失败");
			break;
		}
	}

	@Override
	public void onReq(BaseReq arg0) {
		// TODO 自动生成的方法存根

	}
}

我们在OpenActivity界面加入分享按钮,

Button btn_wx;// 分享好友
private IWXAPI wxApi;
	public static final String WX_APP_ID = "wx********************aa";// 微信分享

// 实例化微信分享实例
		wxApi = WXAPIFactory.createWXAPI(this, WX_APP_ID);
		wxApi.registerApp(WX_APP_ID);


		// 分享好友
		btn_wx = (Button) findViewById(R.id.Button02);
		btn_wx.setOnClickListener(new OnClickListener() {


			@Override
			public void onClick(View v) {
				wechatShare(0);
			}
		});

//flag为0时分享给好友或群,flag为1时分享到朋友圈
private void wechatShare(int flag) {
		WXWebpageObject webpage = new WXWebpageObject();
		webpage.webpageUrl = "http://shouji.baidu/software/item?docid=8554193&from=as";
		WXMediaMessage msg = new WXMediaMessage(webpage);
		msg.title = "也没啥好礼物,就送你500万吧!";
		msg.description = tvKind.getText() + " "
				+ tvNum.getText() + " 。快去买吧,中了别忘了给我分点,呵呵!";
		// 这里替换一张自己工程里的图片资源
		Bitmap thumb = BitmapFactory.decodeResource(getResources(),
				R.drawable.ic_launcher);
		msg.setThumbImage(thumb);
		SendMessageToWX.Req req = new SendMessageToWX.Req();
		req.transaction = String.valueOf(System.currentTimeMillis());
		req.message = msg;
		req.scene = flag == 0 ? SendMessageToWX.Req.WXSceneSession
				: SendMessageToWX.Req.WXSceneTimeline;
		wxApi.sendReq(req);
		Log.e("test", "send");
	}

至此分享功能已实现。


第三大步:广告

这里我拿百度应用来举例:首先在 百度应用开发者平台注册账号,上传自己应用。填写相关信息,等审核通过后。点击获取服务,在广告里添加广告位,会生成对应的广告id,自己应用id。

导入对应jar包,在自己的程序添加

private BDInterstitialAd appxInterstitialAdView;// 插屏广告
	Handler myHandler;


// 处理广告相应
		myHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {
				case 1:
					appxInterstitialAdView.showAd();
					break;
				case 2:
					appxInterstitialAdView.loadAd();
					break;
				}
			}
		};


private void loadAd() {
		// 创建广告视图
		// 发布时请使用正确的ApiKey和广告位ID
		appxInterstitialAdView = new BDInterstitialAd(this,
				"ekYuWDotdIQnLGhQgPDf4Rb0oFwFHfze", "Nx0bOLRLSWkoF1oWYgTo46Lx");
		// 设置插屏广告行为监听器
		appxInterstitialAdView.setAdListener(new InterstitialAdListener() {

			String TAG = "ad";

			@Override
			public void onAdvertisementDataDidLoadFailure() {
				Log.e(TAG, "load failure");
			}

			@Override
			public void onAdvertisementDataDidLoadSuccess() {
				Log.e(TAG, "load success");
			}

			@Override
			public void onAdvertisementViewDidClick() {
				Log.e(TAG, "on click");
			}

			@Override
			public void onAdvertisementViewDidHide() {
				Log.e(TAG, "on hide");
			}

			@Override
			public void onAdvertisementViewDidShow() {
				Log.e(TAG, "on show");
			}

			@Override
			public void onAdvertisementViewWillStartNewIntent() {
				Log.e(TAG, "leave");
			}

		});

		// 加载广告
		appxInterstitialAdView.loadAd();
		new Thread(new Runnable() {

			@Override
			public void run() {
				// 当广告未加载时一直执行
				while (true) {
					try {
						Thread.sleep(3000);
						// 展示插屏广告前先请先检查下广告是否加载完毕
						if (appxInterstitialAdView.isLoaded()) {
							Message msg = new Message();
							msg.what = 1;
							myHandler.sendMessage(msg);
							return;
						} else {
							Message msg = new Message();
							msg.what = 2;
							myHandler.sendMessage(msg);
							Log.i("ad", "AppX Interstitial Ad is not ready");
						}
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}).start();
	}

这时软件基本完成。


希望仓促完成的本文会对您有所启发,彩票助手app使用体验可以点击下面链接

app下载地址

更多推荐

一款彩票app的制作运营详解

本文发布于:2023-06-11 02:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1372705.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详解   彩票   app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!