安卓手机应用(免费和付费) - 告诉图书馆工程类,如果应用程序是免费或付费 [英] Android App versions (Free and Paid) - tell Library Project classes if app is Free or Paid

查看:125
本文介绍了安卓手机应用(免费和付费) - 告诉图书馆工程类,如果应用程序是免费或付费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含所有我的code Android应用程序的项目。我做了这个应用程序一库项目定义在这里机器人。 developer.com。

I have an Android app project that contains all of my code. I've made this "app" a Library project as defined here at android.developer.com..

因此​​,我提出了利用该库项目中的两个新的Andr​​oid项目。每个新项目的新包的名字是:

Consequently, I have made two new Android projects which utilize this library project. The new package names for each of the new projects are:

com.myapps.freeapp
com.myapps.paidapp

正如你可能会看到,我尝试发布免费和付费应用程序的版本。

As you can probably see, I am trying to publish free and paid versions of the app.

什么是告诉库项目已安装的应用程序是否是免费版还是付费版本的最佳方法是什么?

What is the best way to tell the library project whether the installed app is the free version or paid version?

推荐答案

这是从我的博客文章,描述了如何使用库项目,建立一个免费/付费版本。

This is from my blog post that describes how to build a free / paid version using a library project.

通常情况下,您将创建三个项目;一个免费的项目,付费项目和库项目。

Generally, you'll create three projects; a free project, a paid project and a library project.

您会再创建库项目中的一个Build.java文件,像这样的:

You'll then create a Build.java file in your library project such as this:

public class Build {
    public final static int FREE = 1;
    public final static int PAID = 2;
    public static int getBuild(Context context){
        return context.getResources().getInteger(R.integer.build);
    }
}

现在,您将创建在每个项目的build.xml文件资源:

Now, you'll create an build.xml resource in each of your projects:

[库] /resources/values​​/build.xml:

[library]/resources/values/build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <integer name="build">0</integer>
</resources>

[免费] /resources/values​​/build.xml:

[free]/resources/values/build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <integer name="build">1</integer>
</resources>

[付] /resources/values​​/build.xml:

[paid]/resources/values/build.xml:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <integer name="build">2</integer>
</resources>

您将能够检查的版本在运行时:

You will then be able to check for the version at run time:

if (Build.getBuild(context) == Build.FREE){
   // Do the free stuff
} else {
   // Do the paid stuff
}

借助博客文章详细介绍了具体步骤需要在Linux命令行从头创建项目。

The blog post details the exact steps necessary to create the projects from scratch at the Linux command line.

这篇关于安卓手机应用(免费和付费) - 告诉图书馆工程类,如果应用程序是免费或付费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆