データベースに保存された時間値でアラームを再生する必要があるアプリを使用しています。ステートメント「notification.defaults=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE;」を削除すると、アラームを再生せずにそのアラーム時刻に通知が表示されます。アラーム.上記のステートメントを挿入すると、アラームが再生され、アプリケーションが強制的に閉じられます。アラームクラスは次のとおりです。
public class AlarmManager extends BroadcastReceiver {
sampleDatabase appdb;
SQLiteDatabase sqldb;
Cursor cursor;
int today,prev;
Intent in;
@Override
public void onReceive(Context context, Intent intent)
{
NotificationManager manger = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon , "Yahrzeit" , System.currentTimeMillis());
in = new Intent(context,FirstAppActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, in, 0);
notification.setLatestEventInfo(context, "ALERT!!!!", "Time Over" , contentIntent);
notification.defaults=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE;
notification.flags = Notification.FLAG_INSISTENT;
appdb = new sampleDatabase(context);
sqldb = appdb.getReadableDatabase();
cursor = sqldb.query(sampleDatabase.TABLE_SEC, null, null, null, null, null, null);
cursor.moveToFirst();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.SECOND, 0);
today = (int)(cal.getTimeInMillis()/1000);
Log.e("Naga","Alarm");
Log.e("today",Integer.toString(today));
prev = 0;
cursor.moveToPrevious();
while(cursor.moveToNext())
{
int dbdate = cursor.getInt(cursor.getColumnIndex(sampleDatabase.ALARMSET));
int id = cursor.getInt(cursor.getColumnIndex(sampleDatabase.ROW_ID));
Log.e("dbdate",Integer.toString(dbdate));
if((dbdate<=today)&&(dbdate>prev))
{
manger.cancelAll();
manger.notify(1, notification);
sqldb.execSQL("DELETE from " + sampleDatabase.TABLE + " where " + sampleDatabase.ROW_ID + "=" + id);
sqldb.execSQL("DELETE from "+sampleDatabase.TABLE_SEC + " where " + sampleDatabase.ROW_ID + "=" + id);
}
prev = dbdate;
}
cursor.close();
sqldb.close();
}
私のlogcatビューは次のようになります(バイブレーションの許可を挿入しましたが、このエラーも発生します):
11-14 18:09:18.000: ERROR/AndroidRuntime(757): FATAL EXCEPTION: main
11-14 18:09:18.000: ERROR/AndroidRuntime(757): java.lang.RuntimeException: Unable to start receiver com.nagainfo.firstAp.AlarmManager: java.lang.SecurityException: Requires VIBRATE permission
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.ActivityThread.access$3200(ActivityThread.java:125)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.os.Looper.loop(Looper.java:123)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at java.lang.reflect.Method.invoke(Method.java:521)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at dalvik.system.NativeStart.main(Native Method)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): Caused by: java.lang.SecurityException: Requires VIBRATE permission
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.os.Parcel.readException(Parcel.java:1247)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.os.Parcel.readException(Parcel.java:1235)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:274)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.NotificationManager.notify(NotificationManager.java:110)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.NotificationManager.notify(NotificationManager.java:90)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at com.nagainfo.firstAp.AlarmManager.onReceive(AlarmManager.java:52)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
11-14 18:09:18.000: ERROR/AndroidRuntime(757): ... 10 more
助けてください。私のマニフェストは次のとおりです。
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".FirstAppActivity"
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=".addtable"
android:label="@string/app_name">
</activity>
<activity android:name=".showTime"
android:label="@string/app_name">
</activity>
<activity android:name=".edittable"
android:label="@string/app_name">
</activity>
<receiver android:name="AlarmManager">
</receiver>
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.VIBRATE"/>
</application>