I'm producing a custom app launcher in Android Studio using online tutorials, however, whenever I decide to run my application on the built-in emulator it never finds the cannot find the app I am trying to launch/package despite having the correct package name. Any help on this will be much appreciated however I am very very new to Java and Android Studio so keep it simple please thanks!
I've attached my code:
package com.android.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
int view = R.layout.activity_main;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(view);
final LinearLayout parent = findViewById(R.id.parent);
textView = findViewById(R.id.text);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.youtube");
if (launchIntent != null) {
startActivity(launchIntent);
} else {
Toast.makeText(MainActivity.this, "There is no package available in android", Toast.LENGTH_LONG).show();
}
}
});
}
}