2017-01-11 6 views
0

アラームが発生する必要があるアプリケーションを作成しました.Alarm Managerは、いくつかのアクティビティからスケジュールされているときに正常に動作します。再起動時にアラームが削除されるので、私はboot_Receiverを使ってアラームを再スケジュールしました。しかし、問題は、bootreceiverクラスからスケジュールされているときにアラームが発せられないということです。AlarmManagerはブートサービスの受信者からは機能しません

public class NotifyService extends WakefulBroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
    Notification_Holder notifholder; 
    Type t=new TypeToken<Notification_Holder>(){}.getType(); 

    Gson js=new Gson(); 
    notifholder=js.fromJson(intent.getStringExtra("one"),t); 
    Notification_Creator notifcreator=new     Notification_Creator(notifholder.title,notifholder.content,notifholder.cal,context); 
    notifcreator.create_notification(); 
} 
} 

BootReceiverクラス: - - :

public class AtBoot extends BroadcastReceiver { 
SharedPreferences sharedPreferences; 
AlarmManager alarmManager; 
Intent x; 
PendingIntent pendingIntent; 

@Override 
public void onReceive(Context context, Intent intent) { 

    sharedPreferences = context.getSharedPreferences("todoshared", Context.MODE_PRIVATE); 
    String f = sharedPreferences.getString("todolist", null); 
    Gson json = new Gson(); 
    alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
     vClass.notes = Notification_Holder.convert_from_jason(f); 
    x=new Intent(context,NotifyService.class); 
    pendingIntent=PendingIntent.getService(context,2100,x,0); 
    alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),pendingIntent); 
    Vibrator vib=(Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); 
    if(vib.hasVibrator()) { 
     vib.vibrate(1500); 
    } 

}}

マニフェストファイル: -

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 





<application 
    android:allowBackup="true" 
    android:hardwareAccelerated="true" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:icon="@mipmap/ic_launcher" 
    android:theme="@style/MyAppBar"> 


    <activity 
     android:name=".scrapper" 
     android:noHistory="true" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:screenOrientation="portrait"> 

    </activity> 
    <activity 
     android:name=".schedule" 
     android:theme="@style/AppTheme.NoActionBar" /> 
    <activity 
     android:name=".workSpace" 
     android:theme="@style/AppTheme.NoActionBar" /> 

    <receiver android:name=".widget"> 
     <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> 
     </intent-filter> 

     <meta-data 
      android:name="android.appwidget.provider" 
      android:resource="@xml/widget_info" /> 
    </receiver> 

    <service 
     android:name=".widgetService" 
     android:permission="android.permission.BIND_REMOTEVIEWS" /> 

    <receiver android:name=".NotifyService" /> 



    <activity 
     android:name=".showSubject" 
     android:theme="@style/AppTheme.popupTheme" /> 

    <activity android:name=".splashScreen" 
     android:theme="@style/AppTheme.NoActionBar" 
     android:noHistory="true" 
     android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <receiver 
     android:name=".AtBoot" 
     android:enabled="true" 
     android:exported="true" 
     android:label="AtBoot"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.QUICKBOOT_POWERON" /> 
     </intent-filter> 
    </receiver> 

</application> 
...

AlarmManagerクラスを助けてください

バイブレータをAtBootクラスに追加しました。起動時に呼び出されているかどうかを確認しました。そして、電話vibrates..Thisまた、私はそれを考えるクラスは起動時に呼び出されていることを意味しますが、アラームの一部が

答えて

1

を動作しません。私はあなたにもIntentFiltersに
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>

を追加する必要がありますHTCのためだと思います
PendingIntent.getBroadcast(context, 2100, x, 0);
なく

PendingIntent.getService(context,2100,x,0);
0

なければならない問題は、私はcorrecとして代わりpendingIntent.getBroadcastのpendingintent.getServiceを()()を使用したことでしたヴェリスラヴァが指摘していた...

関連する問題