「ジェスチャー」をアクティビティに関連付けるアプリケーションに取り組んでいます(Dolphin BrowserがURLで行うように)。私がやりたいことは、ユーザーが Action.PICK_ACTIVITY でアクティビティを選択できるようにすることです:
Intent data = new Intent(Intent.ACTION_MAIN);
data.addCategory(Intent.CATEGORY_LAUNCHER);
Intent intent = new Intent(Intent.ACTION_PICK_ACTIVITY);
intent.putExtra(Intent.EXTRA_INTENT, data);
startActivityForResult(intent, PICK_ACTIVITY);
...
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_ACTIVITY && resultCode == RESULT_OK) {
Gesture gesture = new Gesture();
gesture.intent = data;
Intent intent = new Intent(this, GestureEditorActivity.class);
intent.putExtra("com.example.gesture.Gesture",gesture.toByteArray());
startActivity(intent);
}
}
そして、ユーザーが関連付けられたジェスチャを描画すると、アクティビティを開始します。
Intent intent = GestureList.getInstance(getApplicationContext()).getIntentForGesture(gesture);//intent corresponds to data in onActivityResult method
if(intent != null)
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
else
Toast.makeText(this, R.string.unrecognized_gesture, Toast.LENGTH_LONG).show();
しかし、私は ActivityNotFoundException を得ました:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN dat=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;component=com.android.calculator2/.Calculator;end }
ここに私の getIntentForGesture メソッドがあります:
public Intent getIntentForGesture(Gesture gesture)
{
float bestDist = Float.MAX_VALUE;
Gesture bestGesture = null;
for(Gesture g:this)
{
float dist = gesture.distance(g);
if(dist < bestDist)
{
bestDist = dist;
bestGesture = g;
}
}
if(bestGesture != null)
return bestGesture.intent;
else
return null;
}
私の壊れた英語で申し訳ありません。あなたの答えを前もって感謝します