package com.codename.spike.project;
import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.util.Log;import android.provider.MediaStore;import android.database.Cursor;
import java.io.File;
import userclasses.StateMachine;
import com.codename.spike.project.CodeNameOneSpikeProjectStub;
import android.content.Context;
public class ShareActivity extends Activity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); String path = null;
if (Intent.ACTION_SEND.equals(action) && type != null) { if (type.startsWith("image/") || type.startsWith("application/pdf")) { try{ Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); if (uri != null) { String filePath = uri.getPath(); File sharedFile = null; String[] projection = { MediaStore.MediaColumns.DATA }; Cursor pathCursor = getContentResolver().query(uri, projection,null, null, null); // Check for a valid cursor if (pathCursor != null && pathCursor.moveToFirst()) { // Get the column index in the Cursor int filenameIndex = pathCursor.getColumnIndex( MediaStore.MediaColumns.DATA); // Get the full file name including path String fileName = pathCursor.getString(filenameIndex); pathCursor.close(); // Create a File object for the filename sharedFile = new File(fileName); }else{ sharedFile = new File(uri.getPath()); } path = sharedFile.getPath(); } Intent startMain = new Intent(this, CodeNameOneSpikeProjectStub.class); startMain.setData(Uri.parse(path)); startMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); this.startActivity(startMain); this.setResult(Activity.RESULT_OK); intent.setData(null); this.finish();
}catch (Throwable e){ Log.e("ShareActivity", e.getMessage()); } } }
}
}