2012-01-24 38 views
1

私は小さなアプリを作りました。それがする唯一のことは、発信コールをキャッチし、発生したときにいくつかのアクティビティを表示することです。ちょうどActivityBroadcastReceiverがあります。BroadcastReceiverのアクティビティを開始

私のコードを別のアプリケーションと統合したいのですが、Manifest.xmlからBroadcastReceiverを削除し、メインアクティビティから動的に作成(登録)しました。私の受信機はうまく発射されましたが、活動は表示されません。

2つの方法の違いは何ですか?

私はどのようにアクティビティを表示できますか? MainActivity.javaから

callInterceptor = new InterceptOutgoingCall(); 
IntentFilter callInterceptorIntentFilter = new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"); 
callInterceptorIntentFilter.setPriority(100); 
registerReceiver(callInterceptor, callInterceptorIntentFilter); 

と機能receiver.onReceive(Context,Intent)から:私が答えを見つけ

<activity android:name=".AlertActivity" 
      android:screenOrientation="portrait"/> 

答えて

1

Intent alertIntent = new Intent(context, AlertActivity.class); 
alertIntent.putExtra("callnumber", phonenbr); 
alertIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(alertIntent); 

私の活動は、このようなmanifestで宣言されています2つのスレッド:マニフェストに

  1. Android launch an activity from a broadcast receiver

  2. Activity started from notification opened on top of the activity stack

、活性がandroid:taskAffinityで宣言されなければなりません。 インテントを開始するときに、フラグを追加する必要がありました= Intent.FLAG_ACTIVITY_NEW_TASK

関連する問題