title: I am not able to launch an android application from another android application. What to do?
body: <p>I am using <code>on receive()</code> to receive broadcast and launch another application(by intent). Whenever the app(wifimann) receives the broadcast, the other app (called kotkot(written in Kotlin)) doesn't launch from initial app despite the Wi-Fi being connected. 
  My code is as follows:</p>
  
  <ul>
  <li><p>MainActivity:</p>
  
  <pre><code>package com.wifi.wifimann;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.net.ConnectivityManager;
  import android.net.NetworkCapabilities;
  import android.net.NetworkInfo;
  import android.os.Bundle;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
  }
  </code></pre></li>
  <li><p>ConnectivityReciever.java:</p>
  
  <pre><code>package com.wifi.wifimann;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.net.ConnectivityManager;
  import android.net.NetworkCapabilities;
  
  import com.wifi.wifimann.MainActivity;
  
  public class ConnectivityReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
          NetworkCapabilities networkAgent = connMgr.getNetworkCapabilities(connMgr.getActiveNetwork());
  //        NetworkInfo wifi = networkAgent.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
          if (networkAgent.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)){
              Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.example.kotkot");
              if (launchIntent != null) {
                  context.startActivity(launchIntent);//null pointer check in case package name was not found
              }
          }
  
      }
  }
  </code></pre>
  
  <ul>
  <li>AndroidManifest.xml</li>
  </ul>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wifi.wifimann"&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;receiver android:name=".MyBroadcastReceiver"  android:exported="true"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
                  &lt;action android:name="android.intent.action.INPUT_METHOD_CHANGED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;activity android:name=".MainActivity"&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;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre></li>
  </ul>
  
  <h1><strong>It also says that MyBroadcastReceiver is unresolved. But my build.gradle has the same pkg name("com.wifi.wifimann") as its application ID.</strong></h1>
  
  <ul>
  <li><p>kotkot:</p>
  
  <ul>
  <li>MainActivity:</li>
  </ul>
  
  <pre><code>
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.widget.TextView
  import androidx.core.content.ContextCompat.startActivity
  import android.content.Intent
  import android.net.ConnectivityManager
  import android.net.NetworkInfo
  import android.content.Context.CONNECTIVITY_SERVICE
  import androidx.core.content.ContextCompat.getSystemService
  import android.content.BroadcastReceiver
  import android.content.Context
  import android.net.NetworkCapabilities
  import android.os.Build
  import androidx.core.content.ContextCompat.getSystemService
  
  
  class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          val welcome_greeting: TextView = findViewById(R.id.welcome_greeting)
          welcome_greeting.setText("kotleenhere!!")
      }
  }
  </code></pre></li>
  </ul>