-
-
Save optedoblivion/1274757 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BuildEnvelope extends Activity { | |
private static Context mContext; | |
@Override | |
public void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
mContext = this; | |
setContentView(R.layout.buildenvelope); | |
try | |
{ | |
Document doc = new Document(); | |
doc.setID(1); | |
Uri uri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); | |
ContentResolver cr = getContentResolver(); | |
Cursor cur = cr.query(uri, null, null, null, null); | |
if (cur.moveToFirst()) | |
{ | |
doc.setName(cur.getString(cur.getColumnIndex(MediaStore.MediaColumns.TITLE))); | |
String filename = cur.getString(cur.getColumnIndex(MediaStore.MediaColumns.DATA)); | |
int lastdot = filename.lastIndexOf('.'); | |
int lastdir = filename.lastIndexOf('/'); | |
if (lastdot <= lastdir) | |
doc.setFileExtension(""); | |
else | |
doc.setFileExtension(filename.substring(lastdot + 1)); | |
InputStream is = cr.openInputStream(uri); | |
byte[] buf = new byte[cur.getInt(cur.getColumnIndex(MediaStore.MediaColumns.SIZE))]; | |
is.read(buf); | |
is.close(); | |
doc.setData(buf); | |
} | |
Recipient recip = new Recipient(); | |
recip.setID(1); | |
recip.setUserName(((DSApplication)getApplication()).getCurrentUser().getUserName()); | |
recip.setSignerName(((DSApplication)getApplication()).getCurrentUser().getUserName()); | |
recip.setEmail(((DSApplication)getApplication()).getCurrentUser().getEmail()); | |
recip.setType(Recipient.Type.Signer); | |
recip.setRoutingOrder(1); | |
recip.setAutoNavigation(true); | |
CustomField cf_appname = new CustomField(); | |
cf_appname.setName("AppName"); | |
cf_appname.setValue("DocuSign Ink Beta"); | |
CustomField cf_platform = new CustomField(); | |
cf_appname.setName("Platform"); | |
cf_appname.setValue("Android"); | |
final Envelope env = new Envelope(); | |
env.setDocuments(Collections.singletonList(doc)); | |
env.setRecipients(Collections.singleton(recip)); | |
ArrayList<CustomField> fields = new ArrayList<CustomField>(); | |
fields.add(cf_appname); | |
fields.add(cf_platform); | |
env.setCustomFields(fields); | |
env.setSubject(doc.getName()); | |
env.setEmailBlurb(""); | |
// if i uncomment the putExtra call, this line has no effect | |
Thread t = new Thread(new Runnable() | |
{ | |
@Override | |
public void run() | |
{ | |
Intent i = new Intent(this, UploadActivity.class); | |
i.putExtra("Envelope", env); | |
startActivity(i); | |
} | |
} | |
t.start(); | |
t.join(); | |
// this works fine | |
finish(); | |
} | |
catch (Exception e) | |
{ | |
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG); | |
finish(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment