キーストアから証明書を取得するための基本的なAsyncTaskを作成しようとしています。
どういうわけか、最も単純なAsyncTaskでさえ私には機能しません、私はExceptionInIntilizationErrorについてのエラーを受け取り続けます。
これは、基本的な非同期タスクを機能させるために使用するテストコードです。
public class Authenticator extends Activity {
PrivateKey privateKey = null;
String SavedAlias = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getCertificates("TEST");
doSomething();
}
public void doSomething()
{
new additionalStuff().execute();
}
public class AliasLoader extends AsyncTask<Void, Void, X509Certificate[]>
{
X509Certificate[] chain = null;
@Override protected X509Certificate[] doInBackground(Void... params) {
android.os.Debug.waitForDebugger();
if(!SavedAlias.isEmpty())
{
try {
chain = KeyChain.getCertificateChain(getApplicationContext(),SavedAlias);
} catch (Exception e) {
// TODO Auto-generated catch block
}
}
else
{
this.cancel(true);
}
return chain;
}
@Override protected void onPostExecute(X509Certificate[] chain)
{
try {
privateKey = KeyChain.getPrivateKey(getApplicationContext(), SavedAlias);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
if (privateKey != null) {
Signature signature = null;
try {
signature = Signature.getInstance("SHA1withRSA");
} catch (NoSuchAlgorithmException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
try {
signature.initSign(privateKey);
} catch (InvalidKeyException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}
}
public void getCertificates(String Host)
{
KeyChainAliasCallback callBack = new KeyChainAliasCallback() {
@Override
public void alias(String alias) {
if (alias != null)
{
saveAlias(alias);
//doSomething();
}
}
};
KeyChain.choosePrivateKeyAlias(this, callBack,
new String[] {"RSA", "DSA"}, // List of acceptable key types. null for any
null, // issuer, null for any
null, // host name of server requesting the cert, null if unavailable
443, // port of server requesting the cert, -1 if unavailable
null); // alias to preselect, null if unavailable
}
public void saveAlias(String alias)
{
SavedAlias = alias;
}
public class additionalStuff extends AsyncTask<String, String, Void>
{
String test = "This is a Test!!!";
@Override
protected void onPreExecute()
{
}
@Override
protected Void doInBackground(String... params) {
return null;
}
@Override
protected void onProgressUpdate(String... values)
{
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(Void unused)
{
Log.d("DEEPAM", "THIS IS A TEST");
return;
}
}
}
なぜこれが失敗するのですか?=(
**更新**事後実行に@Overrideを追加するように変更を加え、パラメーターVoid Voidを追加しても、同じExceptionInInitilizationError =(
**更新**
UIでAsynctaskを使用して新しいスレッドを作成できないと推測していますが、これはおそらく以前は失敗していた理由ですが、ユーザーが証明書を選択すると、とにかくAsyncTaskを呼び出すことができますか?