2

基本的に、次のようにブートレシーバーをセットアップしました。

<receiver
        android:name="com.xxx.xxx.XXX.BootUpReciever"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter android:priority="999" >
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver> code here

現在、これはほとんどの場合うまく機能しているようです。起動時に発火し、必要なことを続けます。ただし、これを私が開発した別のアプリケーションと組み合わせると、登録されているにもかかわらずレシーバーが呼び出されることはありません。

私は常に最初にアプリケーションを実行して登録するようにしていますが、そうではありません。他のアプリケーションをアンインストールすると、機能します。彼らには共有ユーザーがいますが、組み合わせて正常に動作する多くのアプリケーションでそれを使用しているため、それとはあまり関係がないと思います. それがうまくいかないのは、この1つの特定のアプリケーションだけです。

編集:

私は持っていますが<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />、それ以外の場合はまったく機能しません。

そして、ブートレシーバー自体:

public class BootUpReciever extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent args) {
    incBootCounter(context);
    Intent i = new Intent(context, HomeScreenActivity.class);  
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
}

private void incBootCounter(Context ctx) {
    SharedPreferences s = PreferenceManager.getDefaultSharedPreferences(ctx);
    if (s != null) {
        Editor edit = s.edit();
        if (edit != null) {
            edit.putInt("how_many_times_have_we_booted", s.getInt("how_many_times_have_we_booted", 0) + 1);
            edit.commit();
        }
    }
}

}

指摘しておくと、これは Google Play ストアなどにあるアプリケーションではありません。これは、会社として所有するデバイスにのみ展開される非常に特殊なアプリケーションです。

編集2:

ログでいくつかのヘルプを見つけました。他のアプリケーションをインストールすると、次のメッセージが表示されます。

W/BroadcastQueue(  986): Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x8000010 (has extras) } to com.xxx.xxx.xxxxxxxxx/.BootUpReciever requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)

他のアプリケーションがないと、次のメッセージが表示されます。

I/ActivityManager(  980): Start proc com.xxx.xxx.xxxxxx for broadcast com.sps.smc.SMCKiosk/.BootUpReciever: pid=1656 uid=10109 gids={50109, 3003, 3002, 3001, 1028, 1015}
4

2 に答える 2

1

次のようなものを試してください:

public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
      if (context != null) {
        // your codes here
      }
   }
}

最初のチェックでは、action equals のみが処理されることが保証Intent.ACTION_BOOT_COMPLETEDされます。2 番目のチェックでは、コードの実行に有効なコンテキストのみが使用されていることを確認します。

また、AndroidManifest.xml には次の宣言が必要です。

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver
   android:name="com.xxx.xxx.XXX.BootUpReciever">
   <intent-filter android:priority="999" >
      <action android:name="android.intent.action.BOOT_COMPLETED" />
      <action android:name="android.intent.action.QUICKBOOT_POWERON" />    
      <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
</receiver>
于 2014-03-20T16:18:48.127 に答える