title: Cannot run Android app through adb or Appium because of SecurityException: Permission Denial
body: <p>I try to do test automation of Android app. I have activity name and package name from the developer, so it is correct. I have a problem with access to activity. </p>
  
  <p>I researched a lot and I've seen a few similar threads, like those:</p>
  
  <p><a href="https://stackoverflow.com/questions/4162447/android-java-lang-securityexception-permission-denial-start-intent">Android: java.lang.SecurityException: Permission Denial: start Intent</a>
  <a href="https://discuss.appium.io/t/error-a-new-session-could-not-be-created-for-android-appium/2571" rel="nofollow noreferrer">https://discuss.appium.io/t/error-a-new-session-could-not-be-created-for-android-appium/2571</a></p>
  
  <p>When I type <strong>./adb shell am start com.companyname.appname/com.companyname.appname.activities.MainActivity</strong> I get following message:</p>
  
  <pre><code>Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.appname/.activities.MainActivity }
  java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.companyname.appname/.activities.MainActivity } from null (pid=13786, uid=2000) not exported from uid 10101
      at android.os.Parcel.readException(Parcel.java:1465)
      at android.os.Parcel.readException(Parcel.java:1419)
      at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2133)
      at com.android.commands.am.Am.runStart(Am.java:680)
      at com.android.commands.am.Am.onRun(Am.java:270)
      at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
      at com.android.commands.am.Am.main(Am.java:76)
      at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
      at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
      at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>When I try to run the app using Appium, it throws following:</p>
  
  <pre><code>[31mMessage: [0m[31morg.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 9.86 seconds
  Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
  System info: host: 'mareks-Air', ip: '192.168.1.21', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.2', java.version: '1.8.0_31'
  Driver info: io.appium.java_client.AppiumDriver
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
      at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
      at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
      at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:95)
      at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
      at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:126)
      at org.openqa.selenium.remote.RemoteWebDriver.&lt;init&gt;(RemoteWebDriver.java:153)
      at io.appium.java_client.AppiumDriver.&lt;init&gt;(AppiumDriver.java:49)
      at com.companyname.appname.core.AndroidConfig.initDriver(AndroidConfig.java:45)
      at com.companyname.appname.stepdefinitions.android.SetUpStepDefs.beforeScenario(SetUpStepDefs.java:21)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at cucumber.runtime.Utils$1.call(Utils.java:34)
      at cucumber.runtime.Timeout.timeout(Timeout.java:13)
      at cucumber.runtime.Utils.invoke(Utils.java:30)
      at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
      at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:222)
      at cucumber.runtime.Runtime.runHooks(Runtime.java:210)
      at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:200)
      at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
      at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
      at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
      at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
      at cucumber.api.junit.Cucumber.runChild(Cucumber.java:89)
      at cucumber.api.junit.Cucumber.runChild(Cucumber.java:40)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at cucumber.api.junit.Cucumber.run(Cucumber.java:94)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  [0m
  </code></pre>
  
  <p>My manifest file looks like this: 
      
      </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.GET_TASKS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&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;!-- GCM Permisions --&gt;
  &lt;permission
      android:name="com.companyname.appname.permission.C2D_MESSAGE"
      android:protectionLevel="signature" /&gt;
  
  &lt;uses-permission android:name="com.companyname.appname.permission.C2D_MESSAGE" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  
  &lt;!-- &amp;lt;!&amp;ndash; To auto-complete the email text field in the login form with the user's emails &amp;ndash;&amp;gt; --&gt;
  &lt;!-- &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt; --&gt;
  &lt;!-- &lt;uses-permission android:name="android.permission.READ_PROFILE" /&gt; --&gt;
  &lt;!-- &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt; --&gt;
  &lt;application
      android:name=".MyAppName"
      android:allowBackup="true"
      android:configChanges="locale"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:logo="@mipmap/ic_launcher"
      android:theme="@style/AppTheme"&gt;
      &lt;meta-data
          android:name="io.fabric.ApiKey"
          android:value="a602ec90eb6f41f23ad19b0cd98aeb92fe3170a2" /&gt;
  
      &lt;activity
          android:name=".activities.fragments.otherActivities.LoginActivity"
          android:configChanges="orientation|keyboardHidden|screenSize"
          android:windowSoftInputMode="adjustResize|stateVisible"&gt;
          &lt;intent-filter android:label="@string/app_name"&gt;
              &lt;action android:name="android.intent.action.MAIN"
                  android:exported="true"/&gt;
  
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".activities.MainActivity"
          android:configChanges="locale"
          android:label="@string/app_name"&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".activities.fragments.SubActivities.CalendarActivity"
          android:configChanges="orientation|keyboardHidden|screenSize" /&gt;
      &lt;activity
          android:name=".activities.fragments.SubActivities.SurveyActivity"
          android:configChanges="orientation|keyboardHidden|screenSize" /&gt;
      &lt;activity
          android:name=".activities.fragments.SubActivities.ShowContentActivity"
          android:configChanges="orientation|keyboardHidden|screenSize" /&gt;
      &lt;activity
          android:name=".activities.fragments.otherActivities.SettingsActivity"
          android:label="Settings" /&gt;
      &lt;activity
          android:name=".database.sql.AndroidDatabaseManager"
          android:theme="@style/Theme.AppCompat.Light" /&gt;
  
      &lt;provider
          android:name=".database.sql.providers.SurveyProvider"
          android:authorities="com.companyname.appname.survey"
          android:enabled="true"
          android:exported="false" /&gt;
      &lt;provider
          android:name=".database.sql.providers.MainProvider"
          android:authorities="com.companyname.appname.main"
          android:enabled="true"
          android:exported="false" /&gt;
  
      &lt;!-- GCM Stuff --&gt;
      &lt;receiver
          android:name=".gcm.GcmBroadcastReceiver"
          android:permission="com.google.android.c2dm.permission.SEND" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
  
              &lt;category android:name="com.companyname.appname" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;service android:name=".gcm.GcmIntentService" /&gt;
  
      &lt;activity
          android:name=".activities.fragments.SubActivities.PrivacyPolicyActivity"
          android:label="@string/title_activity_privacy_policy"&gt;&lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>