2016-07-28 18 views
1

私は把握できなかった問題があります。私は繰り返しのアラーム放送受信機を持っていて、私は起動時にアラームを再起動するためにBOOT_COMPLETE信号を受信する別の放送受信機を設定しました。コードは他の人のように見上げているので、何が間違っているのか分かりません。Android:私のアラームはBOOTCOMPLETED受信クラスで開始されていません

私のブートレシーバー:

public class DeviceBootReceiver extends BroadcastReceiver { 
Context context2; 

public boolean fileExistance(String fname){ 
    File file = context2.getApplicationContext().getFileStreamPath(fname); 
    return file.exists(); 
} 




public String loadCurrentWhat (String filename){ 
    FileInputStream fileInputStream; 
    String info = ""; 
    try { 
     fileInputStream = context2.getApplicationContext().openFileInput(filename); 
     int count; 
     while ((count=fileInputStream.read()) != -1){ 
      info += Character.toString((char)count); 
     } 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return info; 
} 

@Override 
public void onReceive(Context context, Intent intent) { 
    context2 = context; 
     if (fileExistance("number")){ 
       /* Setting the alarm here */ 
       Intent alarmIntent = new Intent(context, AlarmReceiver.class); 
       PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0); 

       AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
       int interval = 10000; 
       manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent); 
     } 

} 
} 

マイ繰り返しアラーム:

public class AlarmReceiver extends BroadcastReceiver { 


Context context2; 

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

    // For our recurring task, we update the character data in internal storage. 
    context2 = context.getApplicationContext(); 
    UPDATE(); 

} 
} 

私のマニフェスト:

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

    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name=".CardFullView"/> 

    <receiver 
     android:name=".DeviceBootReceiver" 
     android:enabled="true" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
     </intent-filter> 
    </receiver> 

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



</application> 
+1

権限は、マニフェストの「」タグの外側にあります。あなたが 'RECEIVE_BOOT_COMPLETED'パーミッションを持っている場合は、投稿した内容が不明です。 –

+0

@Mikeはいそれは内部にあります。私は外に出て何が起こるかを見ます。 –

+1

@マイケル問題が解決しました。 –

答えて

1

私がこれまで見ることができていたものから、あなたは配置する必要がありますRECEIVE_BOOT_COMPLETED許可外側applicationタグ。

これを試してください。これはうまくいくはずです。

関連する問題