Search in sources :

Example 1 with OnActivityResultListener

use of net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener in project Osmand by osmandapp.

the class GpxUiHelper method addTrack.

@TargetApi(Build.VERSION_CODES.KITKAT)
private static void addTrack(final Activity activity, final AlertDialog dialog) {
    if (activity instanceof MapActivity) {
        final MapActivity mapActivity = (MapActivity) activity;
        ActivityResultListener listener = new ActivityResultListener(OPEN_GPX_DOCUMENT_REQUEST, new OnActivityResultListener() {

            @Override
            public void onResult(int resultCode, Intent resultData) {
                if (resultCode == Activity.RESULT_OK) {
                    if (resultData != null) {
                        Uri uri = resultData.getData();
                        if (mapActivity.getImportHelper().handleGpxImport(uri, false)) {
                            dialog.dismiss();
                        }
                    }
                }
            }
        });
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        // intent.addCategory(Intent.CATEGORY_OPENABLE);
        // intent.setType("application/gpx+xml");
        // intent.setType("text/plain");
        // intent.setType("text/xml");
        intent.setType("*/*");
        mapActivity.registerActivityResultListener(listener);
        activity.startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST);
    }
}
Also used : OnActivityResultListener(net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener) Intent(android.content.Intent) Uri(android.net.Uri) OnActivityResultListener(net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener) ActivityResultListener(net.osmand.plus.activities.ActivityResultListener) SuppressLint(android.annotation.SuppressLint) MapActivity(net.osmand.plus.activities.MapActivity) TargetApi(android.annotation.TargetApi)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 ActivityResultListener (net.osmand.plus.activities.ActivityResultListener)1 OnActivityResultListener (net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener)1 MapActivity (net.osmand.plus.activities.MapActivity)1