0

「ジェスチャー」をアクティビティに関連付けるアプリケーションに取り組んでいます(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;
}

私の壊れた英語で申し訳ありません。あなたの答えを前もって感謝します

4

2 に答える 2

0

FLAG_ACTIVITY_NEW_TASKインテントにフラグを追加する必要があります

Intent intent = GestureList.getInstance(getApplicationContext()).getIntentForGesture(gesture);//intent corresponds to data in onActivityResult method
if (intent != null) {
    try {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
} else {
    Toast.makeText(this, R.string.unrecognized_gesture, Toast.LENGTH_LONG).show();
}
于 2013-06-01T22:28:27.010 に答える
0

電卓アクティビティが見つかりません。おそらくマニフェスト ファイルに問題があるため、次を試してください。

オプション1:

すべてが適切に記述されていることを確認してください。エラーメッセージには次のように記載されています。

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 }

そのスラッシュ/がエラーである可能性があります。

オプション #2:

あなたの場合の重要な点は、別のパッケージ (この特定のジェスチャでは電卓) からアクティビティを開こうとしているということです。したがって、次のように電卓アプリを起動できるかどうかを確認してみてください。

Intent calcInt = new Intent(); 
calcInt.setClassName("com.android.calculator2", "com.android.calculator2.Calculator"); 
startActivity(calcInt); 

この単純なコードで電卓が起動しない場合は、デバイスにデフォルトの電卓がインストールされていないに違いありません。

オプション #3:

Android マニフェスト ファイルを投稿して、確認できるようにします。

于 2013-06-01T22:50:12.400 に答える