OsmAnd/plugins/Osmand-SRTMPlugin/src/net/osmand/srtmPlugin/SRTMPluginActivity.java

62 lines
2.4 KiB
Java
Raw Normal View History

2012-12-11 00:41:08 +01:00
package net.osmand.srtmPlugin;
2016-08-14 23:41:23 +02:00
import net.osmand.srtmPlugin.paid.R;
2012-12-11 00:41:08 +01:00
import android.app.Activity;
2016-08-14 23:41:23 +02:00
import android.app.AlertDialog;
2012-12-11 00:41:08 +01:00
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
public class SRTMPluginActivity extends Activity {
private static final String OSMAND_COMPONENT = "net.osmand"; //$NON-NLS-1$
private static final String OSMAND_COMPONENT_PLUS = "net.osmand.plus"; //$NON-NLS-1$
private static final String OSMAND_ACTIVITY = "net.osmand.plus.activities.MainMenuActivity"; //$NON-NLS-1$
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intentPlus = new Intent();
intentPlus.setComponent(new ComponentName(OSMAND_COMPONENT_PLUS, OSMAND_ACTIVITY));
intentPlus.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
ResolveInfo resolved = getPackageManager().resolveActivity(intentPlus, PackageManager.MATCH_DEFAULT_ONLY);
if(resolved != null) {
stopService(intentPlus);
startActivity(intentPlus);
} else {
Intent intentNormal = new Intent();
intentNormal.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intentNormal.setComponent(new ComponentName(OSMAND_COMPONENT, OSMAND_ACTIVITY));
resolved = getPackageManager().resolveActivity(intentNormal, PackageManager.MATCH_DEFAULT_ONLY);
if (resolved != null) {
stopService(intentNormal);
startActivity(intentNormal);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.osmand_app_not_found));
2015-03-08 00:43:21 +01:00
builder.setPositiveButton(getString(R.string.shared_string_yes), new DialogInterface.OnClickListener() {
2012-12-11 00:41:08 +01:00
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + OSMAND_COMPONENT_PLUS));
try {
stopService(intent);
startActivity(intent);
} catch (ActivityNotFoundException e) {
}
}
});
2015-03-08 08:56:57 +01:00
builder.setNegativeButton(getString(R.string.shared_string_no), null);
2012-12-11 00:41:08 +01:00
builder.show();
}
}
}
}