Android - Trying to test a service on boot (java.lang.SecurityException: Permission Denial)
<p>I've been trying to test a service when a device boots up on android, but I cannot get it to work.
I'm trying to start it with this command from CMD:</p>

<p>(in ..\AppData\Local\Android\sdk\platform-tools)</p>

<pre><code>adb shell am broadcast -a android.intent.action.BOOT_COMPLETED
</code></pre>

<p>or </p>

<pre><code>adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n net.fstab.checkit_android/.MyReceiver
</code></pre>

<p><strong>AndroidManifest.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tabache.sciopero"&gt;

    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;


    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;

    &lt;application
        android:name="com.example.tabache.sciopero.MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"&gt;

        &lt;!-- Declaring broadcast receiver for BOOT_COMPLETED event.  PER FARE UN SERVIZIO AVVIATO ALL'INIZIO --&gt;
        &lt;receiver android:name="com.example.tabache.sciopero.MyReceiver" android:exported="true"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;

        &lt;activity android:name=".MainActivity" android:exported="true"&gt;

            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;&lt;!-- ATTENTION: This was auto-generated to add Google Play services to your project for
     App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. --&gt;
        &lt;meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" /&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<p>my receiver class is this:</p>

<pre><code>public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    System.out.println("MyReceiver !!!!");
    Intent startServiceIntent = new Intent(context, MioServizio.class);

context.startService(startServiceIntent);
}
}
</code></pre>

<p>the answer to my dos command is this:</p>

<pre><code>Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED cat=[android.intent.category.HOME] cmp=net.fstab.checkit_android/.MyReceiver }
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=3715, uid=2000
        at android.os.Parcel.readException(Parcel.java:1683)
        at android.os.Parcel.readException(Parcel.java:1636)
        at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3507)
        at com.android.commands.am.Am.sendBroadcast(Am.java:772)
        at com.android.commands.am.Am.onRun(Am.java:404)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
        at com.android.commands.am.Am.main(Am.java:121)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(NativeMethod)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)
</code></pre>

<p>Why I have this error "java.lang.SecurityException: Permission Denial"?</p>