アンドロイドアプリ初心者です...
SMSのイン/アウトアクティビティを監視し、この事実について通知するContentObserverに基づいて、できるだけ簡単なAndroidバックグラウンド(GUIなし)アプリを作成したいと考えています。
私はこれを持っています:
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 は間違っています...
私は取得しています: アクティビティ 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>