アプリケーションを管理し、アプリを SD カードに移動しようとすると、EXTERNAL_APPLICATIONS_AVAILABLE と BOOT_COMPLETED のブロードキャスト レシーバーが起動します。
これが私の放送受信機です:
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import java.util.Timer;
import java.util.TimerTask;
public class AutoStart extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
if(preferences.getBoolean(context.getString(R.string.autoStartKey), false))
{
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 2, 2, pendingIntent);
boolean showNotification = preferences.getBoolean(context.getString(R.string.showNotificationKey), false);
if(showNotification)
Preferences.setNotification(context);
}
Timer timer = new Timer();
final Context contextTimer = context;
timer.schedule(new TimerTask() {
@Override
public void run() {
Intent i = new Intent(contextTimer, StartupCleaner.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
contextTimer.startActivity(i);
}
}, 10000);
}
}
これが私のマニフェストです:
<receiver android:enabled="true" android:name=".AutoStart"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver android:enabled="true" android:name=".AutoStart"
android:permission="android.permission.EXTERNAL_APPLICATIONS_AVAILABLE">
<intent-filter>
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>