A拉起B可实现的几种方法
(1)包名,特定Activity名拉起
Intent intent = new Intent(Intent.ACTION_MAIN);
/**知道要跳转应用的包命与目标Activity*/
ComponentName componentName = new ComponentName("com.example.demo", "com.example.mobile.module.starter.StarterActivity2");
intent.setComponent(componentName);
intent.putExtra("username", "username");//这里Intent传值
intent.putExtra("password", "password");//这里Intent传值
startActivity(intent);
B应用需要在manifest文件对应Activity添加
android:exported="true"
(2)Action 拉起(这里就是进去启动页)
Intent intent = new Intent();
intent.setAction("com.example.demo.starter.info2");
intent.addCategory("android.intent.category.DEFAULT");
intent.setPackage("com.example.demo");
// intent.putExtra("username", mInstance.encrypt("username"));//这里Intent传值
// intent.putExtra("password", mInstance.encrypt("password"));//这里Intent传值
startActivity(intent);
B应用需要在manifest文件对应Activity配置action、category
<activity
android:name=".module.starter.StarterActivity2"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/TranslucentTheme">
<intent-filter>
<action android:name="com.example.demo.starter.info2" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
(3)url拉起(scheme)
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
try {
// 处理自定义scheme协议
// if (url.startsWith("http") || url.startsWith("https") || url.startsWith("ftp")) {
if (url.contains("mmp.csair.com/manualDetails")) {
try {
// 以下固定写法
final Intent intent = new Intent("com.example.demo.starter.info3",
Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
//传参方法二 采用传参方法二,因为加密之后会出现很多特殊符号,不适用传参方法一
// intent.putExtra("username", mInstance.encrypt("username"));//这里Intent传值
// intent.putExtra("password", mInstance.encrypt("password"));//这里Intent传值
startActivity(intent);
} catch (Exception e) {
// 防止没有安装的情况
e.printStackTrace();
Toast.makeText(activity, "您所打开的第三方App未安装!", Toast.LENGTH_LONG).show();
}
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
/* mWebView.showLog("test Log"); */
}
});
B应用需要在manifest文件对应Activity配置action、category、data
<activity
android:name=".module.starter.StarterActivity3"
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/TranslucentTheme">
<!--需要添加下面的intent-filter配置-->
<intent-filter>
<action android:name="com.example.demo.starter.info3" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="host.deom.com"
android:scheme="http" />
<data
android:host="host.deom.com"
android:scheme="https" />
<data
android:host="host.deom.com"
android:scheme="ftp" />
</intent-filter>
</activity>
网友评论