About Intent in Android

1 show intent

   In most cases, the display intent is to call the intent defined by yourself.

2 hidden diagram

   The hidden diagram should be emphasized here. Most beginners may be confused how to use the hidden diagram and under what circumstances?

   Answer first why is there a hidden diagram? 

     We may use some system activities (such as uninstalling applications, etc.), but we can't display the call, so we can only use the hidden diagram.

Here are the steps of the hidden schematic diagram: look at the source code to find the corresponding action catalog Data/Type/DataAndType

   where?

   Basically it is to call some activity or service or broadcastreceiver of the system or other applications

   how?

   First look at the Android source code, mainly look at the action catagory Data/Type/DataAndType. Note that there may not be all of these, and there may be multiple combinations. You only need to find the one you use.

Here's a piece of code that installs the app:

     Intent intent=new Intent();
        intent.setAction("android.intent.action.VIEW");
        intent.addCategory( "android.intent.category.DEFAULT" );
         // here is the file as the data source if it is the character that uses Content Uri.parse(uriString) 
        intent.setDataAndType(Uri.fromFile(file),"application/ vnd.android.package-archive" );
         // startActivity(intent);
         // The method to get the result returned by opening intent 
        startActivityForResult(intent, 1);

This code call is relatively complete. Note that the two methods setData() and setType() cannot be called at the same time. If they are called at the same time, you can follow the chestnut above and use the method setDataAndType().

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324583759&siteId=291194637