How to Invoke or call one app from another app in Android?

前端 未结 3 1323
星月不相逢
星月不相逢 2021-01-27 08:07

I want to invoke one application from another application.

My Java file code:

Intent intent = new Intent(Intent.ACTION_RUN);
intent.se         


        
3条回答
  •  日久生厌
    2021-01-27 08:31

    I am going to assume that you really mean that you want to launch another app, not another Activity in your app.

    Then there are two ways to do this. You can try using an implicit intent which according to the docs, an (Implicit) intent is "an abstract description of an operation to be performed" that "provides for performing late runtime binding between code in different applications." Sort of like trying to launch a method over the wire using an interface. You cannot be sure exactly what the class of the object that is launched only that it can handle the action and categories that you declare.

    The second approach is an explicit intent, which is more like making a concrete call over the wire. If you know the package and class name this should work.

        Intent intent = new Intent(Intent.ACTION_MAIN);
        //intent.putExtra("plain_text", "Testing");
        intent.setClassName("packagename", "packagename.ClassName"); // Explicit Intent
        try {
            startActivity(intent);
        }
        catch (Exception e)
        {
            Log.d(TAG","onCreate",e);
        }
    }
    

    You can add extra info using flags depending on your needs and where your are trying to launch from.

    JAL

提交回复
热议问题