2012-04-17 4 views
0

Androidアプリに新しいI'amに基づいてアプリのためのAndroidManifest.xmlを作成するための...SMSロガー:どのようにContentObserver

私はContentObserverに基づいて可能アンドロイド背景(非GUI)アプリとして最も簡単なよう作成したいですそれはどんなsmsのin/out活動を監視し、この事実について私に通知するでしょう。

私はこれを持っている:

import android.content.Context; 
import android.database.ContentObserver; 
import android.os.Handler; 
import android.util.Log; 

public class SMSNotifyActivity extends ContentObserver { 
    private static String TAG ="SMSContentObserver"; 

    private Context MContext ; 
    private Handler MHandler; 

    public SMSNotifyActivity(Context Context, Handler Handler) { 
     super(Handler); 
     MContext = Context; 
     MHandler = Handler; 
    } 

    @Override 
    public void onChange(boolean selfChange) { 
     Log.i(TAG, "The Sms Table Has Changed ") ; 
    } 
} 

私はContentObserverのために、私はのAndroidManifest.xmlでサービスを作成する必要があることを知っている:

<service android:name=".SMSNotifyActivity" /> 

と開始時にアプリの起動に権利を付与します。

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

... 

<receiver android:name=".SMSNotifyActivity" > 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" /> 
    </intent-filter> 
</receiver> 

しかし、まだsthは間違っています...

取得

I'am:活動ComponentInfo {com.example.smsnotify/com.example.smsnotify.SMSNotifyActivity}をインスタンス化できません:java.lang.InstantiationExceptionの:com.example.smsnotify.SMSNotifyActivity

私の全体のAndroidManifest.xml :

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.smsnotify" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-sdk android:minSdkVersion="8" /> 
    <uses-permission android:name="android.permission.READ_SMS" /> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <activity 
      android:name=".SMSNotifyActivity" 
      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:name=".SMSNotifyActivity" /> 
     <receiver android:name=".SMSNotifyActivity" > 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      </intent-filter> 
     </receiver> 
    </application> 
</manifest> 

答えて

1

あなたはServiceBroadcastReceiverContentObserverActivityとの混乱のビットを持っています。

ServiceServiceまたはIntentServiceから延長)を作成し、ContentObserverを内部クラスとして配置します。

マニフェストから<activity>タグを削除する必要はありません。

マニフェストの<receiver>要素は、BroadcastReceiver拡張クラスを指す必要があります。 BroadcastReceiver、あなたのマニフェストにこれを入れ、SMSNotifyStarterそれを呼び出す拡張してみてください。

<receiver android:name=".SMSNotifyStarter" > 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" /> 
    </intent-filter> 
</receiver> 

をそして、あなたはブーツの放送するために取得するとき、あなたのServiceを開始します。

関連する問題