34 |
String title; |
String title; |
35 |
|
|
36 |
|
|
37 |
Context context; |
Context context; |
38 |
|
|
39 |
public void checkForUpdates(Context context, String url, String title) { |
|
40 |
|
public void checkForUpdates(Context context, String url, String title, String apkUrl) { |
41 |
this.context = context; |
this.context = context; |
42 |
this.title = title; |
this.title = title; |
43 |
|
|
63 |
|
|
64 |
|
|
65 |
UpdateTask task = new UpdateTask(); |
UpdateTask task = new UpdateTask(); |
66 |
task.execute(url); |
task.execute(url, apkUrl); |
67 |
|
|
68 |
|
|
69 |
} catch (NameNotFoundException e) { |
} catch (NameNotFoundException e) { |
76 |
class UpdateTask extends AsyncTask<String,Void,Void> { |
class UpdateTask extends AsyncTask<String,Void,Void> { |
77 |
boolean result = false; |
boolean result = false; |
78 |
int newestVersion = 0; |
int newestVersion = 0; |
79 |
|
|
80 |
|
String apkUrl; |
81 |
|
|
82 |
@Override |
@Override |
83 |
protected Void doInBackground(String... arg0) { |
protected Void doInBackground(String... arg0) { |
84 |
String requestUrl = arg0[0] + "?version=" + encode(versionName) + "&phone=" + encode(phone_model) + "&android=" + encode(androidVersion); |
String requestUrl = arg0[0] + "?version=" + encode(versionName) + "&phone=" + encode(phone_model) + "&android=" + encode(androidVersion); |
85 |
|
apkUrl = arg0[1]; |
86 |
|
|
87 |
try { |
try { |
88 |
URL url = new URL(requestUrl); |
URL url = new URL(requestUrl); |
89 |
URLConnection conn = url.openConnection(); |
URLConnection conn = url.openConnection(); |
145 |
|
|
146 |
builder.setPositiveButton("Yes", new OnClickListener() { |
builder.setPositiveButton("Yes", new OnClickListener() { |
147 |
public void onClick(DialogInterface dialog, int which) { |
public void onClick(DialogInterface dialog, int which) { |
148 |
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + packageName) ); |
String launchUrl = (apkUrl == null) ? "market://search?q=pname:" + packageName : apkUrl; |
149 |
|
|
150 |
|
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(launchUrl) ); |
151 |
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); |
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); |
152 |
try { |
try { |
153 |
context.startActivity(i); |
context.startActivity(i); |