Google Lizenzprüfung, Code Problem

  • Antworten:1
  • Bentwortet
Jan J.
  • Forum-Beiträge: 18

20.05.2013, 20:04:20 via Website

Hallo liebe Community,

ich habe ein Problem mit meinem Google Lizenz Code. Diesen habe ich zu testzwecken vorerst aus einem Tutorial übernommen.

Der ganze Code steht ganz unten.
Ich bekomme bei
1public void applicationError(ApplicationError errorCode)
leider den Error
ApplicationError cannot be resolved to a type
und ich habe keine Ahnung wie ich ihn weckbekomme. Beim rumprobieren habe ich mal aus
1ApplicationError
1ApplicationErrorReport
gemacht. Danach gibt es keine Probleme und die App startet, jedoch crash sie.

Im Logcat kann ich entnehmen das die Lizenzprüfung zu funktionieren scheint, ich kann daraus aber leider nicht erkennen wieso die App crasht, vermute aber mal das es mit
1ApplicationErrorReport
zusammenhängt da es da eigentlich nicht hingehört.

Könnte mir jemand helfen das Problem zu lösen, wäre äußerst dankbar.

mfg Jan =)

Code:

1public abstract class LicenseCheckActivity extends Activity {
2
3 static boolean licensed = true;
4 static boolean didCheck = false;
5 static boolean checkingLicense = false;
6 static final String BASE64_PUBLIC_KEY = "MY_KEY";
7
8 LicenseCheckerCallback mLicenseCheckerCallback;
9 LicenseChecker mChecker;
10
11 Handler mHandler;
12
13 SharedPreferences prefs;
14
15 // REPLACE WITH YOUR OWN SALT , THIS IS FROM EXAMPLE
16 private static final byte[] SALT = new byte[]{
17 -46, 65, 30, -128, -103, -57, 74, -64, 51, 88, -95, -45, 77, -117, -36, -113, -11, 32, -64,
18 89
19 };
20
21 private void displayResult(final String result) {
22 mHandler.post(new Runnable() {
23 public void run() {
24
25 setProgressBarIndeterminateVisibility(false);
26
27 }
28 });
29 }
30
31 protected void doCheck() {
32
33 didCheck = false;
34 checkingLicense = true;
35 setProgressBarIndeterminateVisibility(true);
36
37 mChecker.checkAccess(mLicenseCheckerCallback);
38 }
39
40 protected void checkLicense() {
41
42 Log.i("LICENSE", "checkLicense");
43 mHandler = new Handler();
44
45 // Try to use more data here. ANDROID_ID is a single point of attack.
46 String deviceId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
47
48 // Library calls this when it's done.
49
50 // Construct the LicenseChecker with a policy.
51 mChecker = new LicenseChecker(
52 this, new ServerManagedPolicy(this,
53 new AESObfuscator(SALT, getPackageName(), deviceId)),
54 BASE64_PUBLIC_KEY);
55
56// mChecker = new LicenseChecker(
57// this, new StrictPolicy(),
58// BASE64_PUBLIC_KEY);
59
60 doCheck();
61 }
62
63 protected class MyLicenseCheckerCallback implements LicenseCheckerCallback {
64
65 public void allow() {
66 Log.i("LICENSE", "allow");
67 if (isFinishing()) {
68 // Don't update UI if Activity is finishing.
69 return;
70 }
71 // Should allow user access.
72 displayResult(getString(R.string.allow));
73 licensed = true;
74 checkingLicense = false;
75 didCheck = true;
76
77 }
78
79 public void dontAllow() {
80 Log.i("LICENSE", "dontAllow");
81 if (isFinishing()) {
82 // Don't update UI if Activity is finishing.
83 return;
84 }
85 displayResult(getString(R.string.dont_allow));
86 licensed = false;
87 // Should not allow access. In most cases, the app should assume
88 // the user has access unless it encounters this. If it does,
89 // the app should inform the user of their unlicensed ways
90 // and then either shut down the app or limit the user to a
91 // restricted set of features.
92 // In this example, we show a dialog that takes the user to Market.
93 checkingLicense = false;
94 didCheck = true;
95
96 showDialog(0);
97 }
98
99 public void applicationError(ApplicationError errorCode) {
100 Log.i("LICENSE", "error: " + errorCode);
101 if (isFinishing()) {
102 // Don't update UI if Activity is finishing.
103 return;
104 }
105 licensed = false;
106 // This is a polite way of saying the developer made a mistake
107 // while setting up or calling the license checker library.
108 // Please examine the error code and fix the error.
109 String result = String.format(getString(R.string.application_error), errorCode);
110 checkingLicense = false;
111 didCheck = true;
112
113 //displayResult(result);
114 showDialog(0);
115 }
116
117 @Override
118 public void allow(int reason) {
119 // TODO Auto-generated method stub
120
121 }
122
123 @Override
124 public void dontAllow(int reason) {
125 // TODO Auto-generated method stub
126
127 }
128
129 @Override
130 public void applicationError(int errorCode) {
131 // TODO Auto-generated method stub
132
133 }
134 }
135
136 protected Dialog onCreateDialog(int id) {
137 // We have only one dialog.
138 return new AlertDialog.Builder(this)
139 .setTitle(R.string.unlicensed_dialog_title)
140 .setMessage(R.string.unlicensed_dialog_body)
141 .setPositiveButton(R.string.buy_button, new DialogInterface.OnClickListener() {
142 public void onClick(DialogInterface dialog, int which) {
143 Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
144 "http://market.android.com/details?id=" + getPackageName()));
145 startActivity(marketIntent);
146 finish();
147 }
148 })
149 .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
150 public void onClick(DialogInterface dialog, int which) {
151 finish();
152 }
153 })
154
155 .setCancelable(false)
156 .setOnKeyListener(new DialogInterface.OnKeyListener(){
157 public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
158 Log.i("License", "Key Listener");
159 finish();
160 return true;
161 }
162 })
163 .create();
164
165 }
166
167 @Override
168 protected void onDestroy() {
169 super.onDestroy();
170 if (mChecker != null) {
171 Log.i("LIcense", "distroy checker");
172 mChecker.onDestroy();
173 }
174 }
175
176}

Logcat:
105-20 17:59:16.505: E/Trace(1036): error opening trace file: No such file or directory (2)
205-20 17:59:16.877: D/dalvikvm(1036): GC_FOR_ALLOC freed 44K, 7% free 2459K/2620K, paused 112ms, total 129ms
305-20 17:59:17.195: I/dalvikvm-heap(1036): Grow heap (frag case) to 17.772MB for 16000016-byte allocation
405-20 17:59:17.265: D/dalvikvm(1036): GC_FOR_ALLOC freed 1K, 1% free 18083K/18248K, paused 67ms, total 67ms
505-20 17:59:17.365: D/dalvikvm(1036): GC_CONCURRENT freed <1K, 1% free 18083K/18248K, paused 4ms+35ms, total 100ms
605-20 17:59:24.735: I/LICENSE(1036): checkLicense
705-20 17:59:25.035: I/LicenseChecker(1036): Binding to licensing service.
805-20 17:59:25.045: E/LicenseChecker(1036): Could not bind to service.
905-20 17:59:25.056: D/AndroidRuntime(1036): Shutting down VM
1005-20 17:59:25.065: W/dalvikvm(1036): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
1105-20 17:59:25.085: E/AndroidRuntime(1036): FATAL EXCEPTION: main
1205-20 17:59:25.085: E/AndroidRuntime(1036): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.marcoriege.laufkompass_pro/de.marcoriege.laufkompass_pro.MainActivity}: java.lang.NullPointerException
1305-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
1405-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
1505-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.ActivityThread.access$600(ActivityThread.java:141)
1605-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
1705-20 17:59:25.085: E/AndroidRuntime(1036): at android.os.Handler.dispatchMessage(Handler.java:99)
1805-20 17:59:25.085: E/AndroidRuntime(1036): at android.os.Looper.loop(Looper.java:137)
1905-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.ActivityThread.main(ActivityThread.java:5041)
2005-20 17:59:25.085: E/AndroidRuntime(1036): at java.lang.reflect.Method.invokeNative(Native Method)
2105-20 17:59:25.085: E/AndroidRuntime(1036): at java.lang.reflect.Method.invoke(Method.java:511)
2205-20 17:59:25.085: E/AndroidRuntime(1036): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
2305-20 17:59:25.085: E/AndroidRuntime(1036): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
2405-20 17:59:25.085: E/AndroidRuntime(1036): at dalvik.system.NativeStart.main(Native Method)
2505-20 17:59:25.085: E/AndroidRuntime(1036): Caused by: java.lang.NullPointerException
2605-20 17:59:25.085: E/AndroidRuntime(1036): at com.google.android.vending.licensing.LicenseChecker.handleServiceConnectionError(LicenseChecker.java:299)
2705-20 17:59:25.085: E/AndroidRuntime(1036): at com.google.android.vending.licensing.LicenseChecker.checkAccess(LicenseChecker.java:161)
2805-20 17:59:25.085: E/AndroidRuntime(1036): at de.marcoriege.laufkompass_pro.LicenseCheckActivity.doCheck(LicenseCheckActivity.java:58)
2905-20 17:59:25.085: E/AndroidRuntime(1036): at de.marcoriege.laufkompass_pro.LicenseCheckActivity.checkLicense(LicenseCheckActivity.java:81)
3005-20 17:59:25.085: E/AndroidRuntime(1036): at de.marcoriege.laufkompass_pro.MainActivity.onCreate(MainActivity.java:35)
3105-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.Activity.performCreate(Activity.java:5104)
3205-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
3305-20 17:59:25.085: E/AndroidRuntime(1036): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
3405-20 17:59:25.085: E/AndroidRuntime(1036): ... 11 more
3505-20 18:00:22.754: I/Process(1036): Sending signal. PID: 1036 SIG: 9



EDIT:

Falls jemand diese Problem auch mal haben sollte, mein Fehler lag daran das mehrere Verweise auf objekte genutz werden sollten die es aber nicht in meiner App gab. (musste diese Verweise also entfernen)

— geändert am 23.05.2013, 12:16:04

Antworten
Jan J.
  • Forum-Beiträge: 18

22.05.2013, 10:58:35 via Website

Push

Kann mir niemand helfen?

Antworten