如何许可我的Android应用程序? [英] How to license my Android application?
问题描述
我只是接近完成我的Android应用程序。现在我要上传我的应用程序在Android市场的付费应用。对于我已经从Android网站阅读文档:
I am just near to complete my Android application. And now I want to upload my application on Android market for paid application. For that I have read the document from the Android site:
但我想看到任何的演示,或已为Android应用程序做了这样的许可任何项目。我见过mainactivity的Android开发者网站上的演示。但是,也有处理程序,并给出我想要实现code到项目mymainactivity。 在mymainactivity没有在启动应用程序的启动画面。而且我还设立一个处理它。所以,这就是为什么我需要任何实际的例子来看看如何实现我们自己的应用程序的许可。
But I want to see any demo or any project that have done such licensing for the android application. I have seen demo of the android developer site of mainactivity. But there there are handler is given and I want to implement that code in to mymainactivity of the project. In mymainactivity there is a splash screen in starting of the application. And I have also set one handler for it. So thats why I need any example to see how to implement the licensing in our own application.
另一件事我想知道的是,这是强制执行的Android许可上传付费应用程序在Android市场上?
Another thing I want to know is, is this compulsory to implement Android licensing for to upload paid application on the Android market?
是否有可能作为支付与出实施许可的Android应用程序,设置应用程序?
因此,如果有任何可用的演示?请给我一个链接,说。
Is it possible to set the application as paid with out implementing the licensing to the Android application?
So if there are any demo available? Please give me a link for that.
我真的需要它做的事。所以请帮助我吧。
I realy need it to do. So help me for it.
推荐答案
在开始之前,请确保您已包括在项目中的许可证库按如下说明: 授权您的应用程序| Android开发者
Before you start, Make you have included the license library in your project as explained here: Licensing Your Applications | Android Developers
-
请一个新的活动在您的项目称为LicenseCheck.java
Make a new Activity in your project called LicenseCheck.java
粘贴在活动如下:
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.widget.Toast;
import com.android.vending.licensing.AESObfuscator;
import com.android.vending.licensing.LicenseChecker;
import com.android.vending.licensing.LicenseCheckerCallback;
import com.android.vending.licensing.ServerManagedPolicy;
/**
* NOTES ON USING THIS LICENSE FILE IN YOUR APPLICATION:
* 1. Define the package
* of you application above
* 2. Be sure your public key is set properly @BASE64_PUBLIC_KEY
* 3. Change your SALT using random digits
* 4. Under AllowAccess, Add your previously used MainActivity
* 5. Add this activity to
* your manifest and set intent filters to MAIN and LAUNCHER
* 6. Remove Intent Filters from previous main activity
*/
public class LicenseCheck extends Activity {
private class MyLicenseCheckerCallback implements LicenseCheckerCallback {
@Override
public void allow() {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should allow user access.
startMainActivity();
}
@Override
public void applicationError(ApplicationErrorCode errorCode) {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// This is a polite way of saying the developer made a mistake
// while setting up or calling the license checker library.
// Please examine the error code and fix the error.
toast("Error: " + errorCode.name());
startMainActivity();
}
@Override
public void dontAllow() {
if (isFinishing()) {
// Don't update UI if Activity is finishing.
return;
}
// Should not allow access. In most cases, the app should assume
// the user has access unless it encounters this. If it does,
// the app should inform the user of their unlicensed ways
// and then either shut down the app or limit the user to a
// restricted set of features.
// In this example, we show a dialog that takes the user to Market.
showDialog(0);
}
}
private static final String BASE64_PUBLIC_KEY = "PLACE YOUR BASE KEY FROM GOOGLE HERE";
private static final byte[] SALT = new byte[] { INPUT 20 RANDOM INTEGERS HERE };
private LicenseChecker mChecker;
// A handler on the UI thread.
private LicenseCheckerCallback mLicenseCheckerCallback;
private void doCheck() {
mChecker.checkAccess(mLicenseCheckerCallback);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Try to use more data here. ANDROID_ID is a single point of attack.
String deviceId = Secure.getString(getContentResolver(),
Secure.ANDROID_ID);
// Library calls this when it's done.
mLicenseCheckerCallback = new MyLicenseCheckerCallback();
// Construct the LicenseChecker with a policy.
mChecker = new LicenseChecker(this, new ServerManagedPolicy(this,
new AESObfuscator(SALT, getPackageName(), deviceId)),
BASE64_PUBLIC_KEY);
doCheck();
}
@Override
protected Dialog onCreateDialog(int id) {
// We have only one dialog.
return new AlertDialog.Builder(this)
.setTitle("Application Not Licensed")
.setCancelable(false)
.setMessage(
"This application is not licensed. Please purchase it from Android Market")
.setPositiveButton("Buy App",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
Intent marketIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://market.android.com/details?id="
+ getPackageName()));
startActivity(marketIntent);
finish();
}
})
.setNegativeButton("Exit",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
finish();
}
}).create();
}
@Override
protected void onDestroy() {
super.onDestroy();
mChecker.onDestroy();
}
private void startMainActivity() {
startActivity(new Intent(this, MainActivity.class)); //REPLACE MainActivity.class WITH YOUR APPS ORIGINAL LAUNCH ACTIVITY
finish();
}
public void toast(String string) {
Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}
}
修改基本密钥,以提供一个谷歌,将20个随机整数中的盐,更改MainActivity.class到应用程序的主要活动。
Change the Base Key to the one google provided, Place 20 random integers in the SALT, Change MainActivity.class to the Main Activity of your application.
更新您的清单文件与新的活动
Update your Manifest File with the new activity
<!-- Old Launch Activity Here -->
<activity android:label="@string/app_name" android:name=".MainActivity" />
<!-- New License Launch Activity with all intent filters from your previous main activity -->
<!-- Translucent.NoTitleBar is so that this activity is never shown to the user -->
<activity android:label="@string/app_name" android:name=".LicenseCheck"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
添加权限在清单标记,但没有在应用程序标签
Add Permission In the manifest Tag but not in the application tag
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
大功告成!确保你测试出来之前发布 :):)
这篇关于如何许可我的Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!