1

I have a task to create an android application that has a one button and it will run an another android application. But I'm not the one who created that another application, so I did some research for my first android app. I found that I need to get the package and class name of the app to run the other application, so I got a third party application to get the package and class name of an app. This is the code and it works:

public class MainActivity extends AppCompatActivity {

    private String pckage_name = "com.sample.package";
    private String clss_name = "com.sample.function.class";
    private Button bt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bt = (Button) findViewById(R.id.button);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                launchCall();

            }
        });

    }



    private void launchCall() {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setComponent(new ComponentName(pckage_name, clss_name));
        try {
            startActivity(intent);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

When that app opens, it has buttons that I need to click so it functions will run, but what I'm trying to do is to run that automatically from my app with just one click of a button. I don't know if the other class name is the one I'll use to run the buttons automatically using my app, or is it wrong?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Ganzo Palumi
  • 77
  • 2
  • 12

0 Answers0