2011-07-09 28 views
0

ブロードキャスト受信機を発信呼び出し用にテストしようとしています。助けてください。ここでブロードキャスト受信機が動作していません

は私のCallCounterクラスです:

package com.callout; 

import android.content.Context; 
import android.content.Intent; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 


public class CallCounter extends PhoneStateListener { 

public void onCallStateChanged(int state, String incomingNumber) { 
    switch(state) { 
     case TelephonyManager.CALL_STATE_IDLE: 
       Log.d("Tony+++++++++++","Outgoing Call finished"); 
       // Call Finished -> stop counter and store it. 
    //    callStop=new Date().getTime(); 
       Context c = getApplicationContext(); 

       c.stopService(new Intent(c,ListenerContainer.class)); 

      break; 
     case TelephonyManager.CALL_STATE_OFFHOOK: 
       Log.d("++++++++++++++++Tony","Outgoing Call Starting"); 
       // Call Started -> start counter. 
       // This is not precise, because it starts when calling, 
       // we can correct it later reading from call log 
     //   callStart=new Date().getTime(); 
      break; 
    } 
} 

private Context getApplicationContext() { 
    // TODO Auto-generated method stub 
    return this.getApplicationContext(); 

} 
} 

ここmyReceiver

ここ
package com.callout; 

import android.content.BroadcastReceiver; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 

    public class myReceiver extends BroadcastReceiver { 
    public void onReceive(Context context, Intent intent) { 
     if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) { 
     Log.d("T+++++++++++++++++ony","In mYRecieverrr"); 
     context.startService(new Intent(context,ListenerContainer.class)); 
     } 
    } 
    } 

がmyServiceというされている:

package com.callout; 

import android.app.Service; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Binder; 
import android.os.IBinder; 
import android.telephony.PhoneStateListener; 
import android.telephony.TelephonyManager; 
import android.util.Log; 

    public class ListenerContainer extends Service { 
    public class LocalBinder extends Binder { 
     ListenerContainer getService() { 
     Log.d("Tony","OKKK HEREEEEEEEEEEEEEeEEEEE"); 
      return ListenerContainer.this; 
     } 
    } 
    @Override 
    public void onStart(Intent intent, int startId) { 
     TelephonyManager tManager =(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 

     CallCounter callCounter=new CallCounter(); 
     tManager.listen(callCounter,PhoneStateListener.LISTEN_CALL_STATE); 

     Log.d("To++++++++++++++ny","Call COUNTER Registered"); 
    } 
    @Override 
    public IBinder onBind(Intent intent) { 
     return mBinder; 
    } 

private final IBinder mBinder = new LocalBinder(); 
} 

とIMは、いくつかの権限が不足している場合、これはマニフェストファイルされます:

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.callout" 
    android:versionCode="1" 
    android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8" /> 
    <uses-permission android:name="android.permission.READ_CONTACTS" /> 
    <uses-permission android:name="android.permission.CALL_PHONE"/> 
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" /> 

    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".CallCounter" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
     </activity> 
      <activity android:name=".myReceiver" 
       android:label="@string/app_name"> 
      <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
        <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
      </activity> 
       <service android:enabled="true" android:name=".ListenerContainer" /> 
      <receiver android:name=".myReceiver"> 
      <intent-filter> 
      <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 
     </intent-filter> 
     </receiver> 
    </application> 

</manifest> 

私の間違いを指摘してください。あなたの受信機は、マニフェストファイルで属性が欠落しているように見えます

+3

はあなたが私たちの水晶玉に見えることを期待してください、あなたの要件を満たし、ここで、完全なソースとのワーキングソリューションがありますか?どのようなエラーが出るのですか、LogCatには何が表示されていますか、何が動作していませんか? –

+1

コードをトレースします。 – Snicolas

+0

不完全な質問のため申し訳ありませんが、誤ってログ部分が削除されました。受信者はf9を実行し、サービスを開始しようとします。コードをトレースすると、onstart()メソッドが実行されることがわかりましたが、その後はphonestatelistenerの部分が開始されません。これはエラーの種類です:/ AndroidRuntime(288):致命的例外:メインE/AndroidRuntime(288):java.lang.RuntimeException:Intentでサービスを開始できません[email protected] {cmp = com.callout/.ListenerContainer}:java.lang.SecurityException:ユーザー10042も現在のプロセスもAndroid.permissionを持っていません.READ_PHONE_STATE – Swati

答えて

1

:エクスポートされた属性で

http://developer.android.com/guide/topics/manifest/receiver-element.html

見て、他のアプリからの放送を受信するためにTOT trueに設定する必要があります。あなたはphonestatelistenerを登録しているので

よろしく、 ステファン

+0

@Stephane:答えをいただきありがとうございますが、他のアプリからのブロードキャストを受信して​​いません。私の場合、サービスは正常に動作しますが、phonestatelistenerはインスタンス化されていません。助けてください – Swati

+0

試しましたか?世界的な放送とは、アプリローカル放送ではないということです。 – Snicolas

2

はあなたのマニフェストに次の権限を追加する必要があります。

<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
関連する問題