Created
October 8, 2015 14:58
-
-
Save wpride/7b8aba0c4a3eb13523a1 to your computer and use it in GitHub Desktop.
Case Content Reader and Broadcast Receiver
This file contains 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
package com.dimagi.test.external; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.os.Parcel; | |
import android.util.Pair; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.Toast; | |
import java.security.GeneralSecurityException; | |
import java.security.KeyFactory; | |
import java.security.SecureRandom; | |
import java.security.interfaces.RSAPublicKey; | |
import java.security.spec.KeySpec; | |
import java.security.spec.X509EncodedKeySpec; | |
import javax.crypto.Cipher; | |
import javax.crypto.KeyGenerator; | |
import javax.crypto.SecretKey; | |
public class ExternalAppActivity extends Activity { | |
Button login; | |
Button sync; | |
Button content; | |
Button media; | |
Button receiver; | |
Button fixtureButton; | |
byte[] publicKey; | |
String keyId; | |
public static final int KEY_REQUEST_CODE = 1; | |
/* | |
* (non-Javadoc) | |
* @see android.app.Activity#onCreate(android.os.Bundle) | |
*/ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
Button ac = (Button)this.findViewById(R.id.acquire_key); | |
ac.setOnClickListener(new OnClickListener() { | |
public void onClick(View v) { | |
Intent i = new Intent("org.commcare.dalvik.action.CommCareKeyAccessRequest"); | |
ExternalAppActivity.this.startActivityForResult(i, KEY_REQUEST_CODE); | |
} | |
}); | |
} | |
/* (non-Javadoc) | |
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent) | |
*/ | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if(requestCode == KEY_REQUEST_CODE) { | |
if(resultCode ==Activity.RESULT_OK) { | |
keyId = data.getStringExtra("commcare_sharing_key_id"); | |
publicKey = data.getByteArrayExtra("commcare_sharing_key_payload"); | |
} else { | |
Toast.makeText(this, "Key Request Denied!", Toast.LENGTH_LONG).show(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment