設定された回数連続して電話を再起動することになっている基本的な Android アプリケーションがあります。これを行うには、電話の起動時にアプリケーションを起動する必要があります。そのために、私は基本的にここにある指示に従い、権限をマニフェストに追加し、アクティビティを開始する BroadcastReceiver クラスを作成しました。これが私の関連コードの一部です:
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("StartMyServiceAtBootReceiver called.");
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
// Intent activityIntent = new Intent("com.example.rebooter.MainActivity");
Intent activityIntent = new Intent(context,MainActivity.class);
activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activityIntent);
}
}
}
マニフェスト ファイルから:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rebooter"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</activity>
<service
android:name=".RebootManager"
android:label="Reboot Manager" >
<action android:name="com.example.rebooter.RebootManager" />
</service>
<receiver android:name=".StartMyServiceAtBootReceiver"
android:enabled="true"
android:exported="true"
android:label="StartMyServiceAtBootReceiver" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</receiver>
</application>
Eclipse エミュレーターでは、アプリケーションは正しく動作しているように見えます。つまり、私のエミュレーターはルート化されておらず、電話機は再起動コマンドを正しく実行しませんが、起動時に正しいアクティビティが開始されることがわかります。
今、Android 4.0.4 を実行している特定のシステムで試してみると、起動時の起動を除いて、アプリケーションのすべてが正常に動作しています。何か案は?
起動時に起動する別のアプリケーションをインストールし、起動時に実際に起動することを確認し、実行中のアプリの下に実際に表示されることを確認して、ハードウェアの問題の可能性を排除しようとしました (私は市販の電話を使用していないため)。起動後にキャッシュされたプロセスとして。
助けていただければ幸いです。追加情報が必要な場合はお知らせください。