From 39fa41f8815f2ead9a71140af0b4e5e7d4924977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Tue, 1 Mar 2016 00:04:22 +0100 Subject: Backup example --- .../openpgp/example/OpenPgpApiActivity.java | 23 ++++++++++++++++++++++ example/src/main/res/layout/openpgp_provider.xml | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java index 3ebe9b4..992f8be 100644 --- a/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java +++ b/example/src/main/java/org/openintents/openpgp/example/OpenPgpApiActivity.java @@ -63,6 +63,7 @@ public class OpenPgpApiActivity extends Activity { public static final int REQUEST_CODE_GET_KEY_IDS = 9915; public static final int REQUEST_CODE_DETACHED_SIGN = 9916; public static final int REQUEST_CODE_DECRYPT_AND_VERIFY_DETACHED = 9917; + public static final int REQUEST_CODE_BACKUP = 9918; @Override public void onCreate(Bundle savedInstanceState) { @@ -83,6 +84,7 @@ public class OpenPgpApiActivity extends Activity { mGetKeyIdsEdit = (EditText) findViewById(R.id.crypto_provider_demo_get_key_ids_edit); Button getKey = (Button) findViewById(R.id.crypto_provider_demo_get_key); Button getKeyIds = (Button) findViewById(R.id.crypto_provider_demo_get_key_ids); + Button backup = (Button) findViewById(R.id.crypto_provider_demo_backup); cleartextSign.setOnClickListener(new View.OnClickListener() { @Override @@ -132,6 +134,12 @@ public class OpenPgpApiActivity extends Activity { getKeyIds(new Intent()); } }); + backup.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + backup(new Intent()); + } + }); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); String providerPackageName = settings.getString("openpgp_provider_list", ""); @@ -401,6 +409,17 @@ public class OpenPgpApiActivity extends Activity { api.executeApiAsync(data, null, null, new MyCallback(false, null, REQUEST_CODE_GET_KEY_IDS)); } + public void backup(Intent data) { + data.setAction(OpenPgpApi.ACTION_BACKUP); + data.putExtra(OpenPgpApi.EXTRA_KEY_IDS, new long[]{Long.decode(mGetKeyEdit.getText().toString())}); + data.putExtra(OpenPgpApi.EXTRA_BACKUP_SECRET, true); + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + + OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); + api.executeApiAsync(data, null, os, new MyCallback(true, os, REQUEST_CODE_BACKUP)); + } + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); @@ -447,6 +466,10 @@ public class OpenPgpApiActivity extends Activity { getKeyIds(data); break; } + case REQUEST_CODE_BACKUP: { + backup(data); + break; + } } } } diff --git a/example/src/main/res/layout/openpgp_provider.xml b/example/src/main/res/layout/openpgp_provider.xml index 13096b4..d2b4572 100644 --- a/example/src/main/res/layout/openpgp_provider.xml +++ b/example/src/main/res/layout/openpgp_provider.xml @@ -153,7 +153,7 @@ +