Android evokes app in many ways

Keywords: Android xml Attribute

Method 1 (aroused by Intent)

Our own app Code:

ComponentName componetName = new ComponentName(                               
"com.lh.jimtrency.webviewdemo",
"com.lh.jimtrency.webviewdemo.MainActivity");
 //(package name of another application, Activity to start)

  Bundle bundle = new Bundle();
  ArrayList<String> strings=new ArrayList<>();
  strings.add("18883250894");
  strings.add("Bravado cabbage");
  bundle.putStringArrayList("userInfo", strings);

  Intent intent = new Intent();
  intent.putExtras(bundle);
  intent.setComponent(componetName);
  startActivity(intent);

PS: com.lh.jimtrency.webviewdemo is the package name of the other party
com.lh.jimtrency.webviewdemo.MainActivity Is the mainactivity class of the other party

The above code calls up the MainActivity class of the other party's App. How does the other party need to configure it? In fact, you just need to AndroidManifest.xml When configuring the MainActivity of, add this attribute (exported)

  <activity
        android:name=".MainActivity"
        android:exported="true"/>

How can the other party accept it?

Bundle bundle=getIntent().getExtras();
if (bundle!=null){   

    Toast.makeText(this,
    bundle.getStringArrayList("userInfo").toString()
   ,Toast.LENGTH_SHORT).show();

}

Method 2 (evoking app through Uri)

In fact, it is also very simple, just in a different way. However, readers must have a certain connection to the uri format http://blog.csdn.net/harvic880925/article/details/44679239).

Let's take a look at how to write our app Code:

Uri uri = Uri.parse("jimtrency://user.info.detail?password=1");

Intent intent = new Intent("android.jimtrency.schemeurl.activity");
intent.setData(uri);
startActivity(intent);

PS: “ android.jimtrency.schemeurl.activity "is the action when jumping

"jimtrency" is the scheme of Uri

" user.info.detail ”For authority

How can the app accept it?

    Intent intent = getIntent();

    if (null != intent) {
        Uri uri = intent.getData();
        if (uri == null) {
            return;
        }
        String acionData = uri.getQueryParameter("password");
        Toast.makeText(this,acionData,Toast.LENGTH_SHORT).show();

    }

Other app's AndroidManifest.xml Configuration of

<activity
android:name=".MainActivity">
<intent-filter>
    <action android:name="android.jimtrency.schemeurl.activity" />
    <category android:name="android.intent.category.DEFAULT" />
    <data
        android:scheme="jimtrency"
        android:host="user.uri.activity" />
</intent-filter>
</activity>

Special emphasis is placed on:

When uri jumps, the action configuration and category configuration must not be missing. The category configuration is fixed. As follows:

   <category android:name="android.intent.category.DEFAULT" />

Method 3 (simple and crude: calling app directly through package name)

PackageManager packageManager = getPackageManager();
Intent intent=new Intent();
intent = packageManager.getLaunchIntentForPackage("com.cmcc.jzfpb");
startActivity(intent);

Posted by kaze on Tue, 14 Jul 2020 08:49:12 -0700