一、显式意图来跳转到第三方应用

   /**
* 这个方法会在点击按钮的时候执行
* @param view
*/ public void skip2Browser(View view){ Log.d(TAG,"skp2Browser");
Intent intent =new Intent();
/**
* 組件的名称,也就是ComponentName =包名/类的路径名称,如包名一直,类的路径名称可以省略包名
* 如:com.google.android.as/com.google.android.apps.miphone.aiai.app.AiAiPredictionService
*/
//第一种写法
// intent.setClassName("com.google.android.as","com.google.android.apps.miphone.aiai.app.AiAiPredictionService"); //第二种写法
ComponentName componentName=new ComponentName("com.google.android.as","com.google.android.apps.miphone.aiai.app.AiAiPredictionService");
intent.setComponent(componentName); startActivity(intent);
}

点击按钮

实现跳转

二、隐式意图来跳转到第三方应用

 /**
* 下面通过隐式意图来跳转到第三方应用
* 1、创建Intent对象
* 2、第二步给intent对象,设置Action、category,5.1以上要设置包名
* 3、startActivity(intent)
* @param view
*/
public void skip2BrowserInvisible(View view) {
Intent intent =new Intent();
intent.setAction("android.intent.action.SEARCH");
intent.addCategory("android.intent.category.DEFAULT");
intent.setPackage("com.google.android.as");
startActivity(intent);
}

activity_skip2browser.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"> <Button
android:layout_width="match_parent"
android:text="跳转到浏览器(显式)"
android:onClick="skip2BrowserVisible"
android:layout_centerInParent="true"
android:layout_height="wrap_content"> </Button>
<Button
android:layout_width="match_parent"
android:text="跳转到浏览器(隐式)"
android:onClick="skip2BrowserInvisible"
android:layout_centerInParent="true"
android:layout_height="wrap_content"> </Button>
</LinearLayout>

Skip2BrowserActivity.java

package com.example.activitydemo;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View; import androidx.annotation.Nullable; public class Skip2BrowserActivity extends Activity { private static final String TAG = "Skip2BrowserActivity"; @Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_skip2browser);
} /**
* 这个方法会在点击按钮的时候执行
* @param view
*/ public void skip2BrowserVisible(View view){ Log.d(TAG,"skp2Browser");
Intent intent =new Intent();
/**
* 組件的名称,也就是ComponentName =包名/类的路径名称,如包名一直,类的路径名称可以省略包名
* 如:com.google.android.as/com.google.android.apps.miphone.aiai.app.AiAiPredictionService
*/
//第一种写法
// intent.setClassName("com.google.android.as","com.google.android.apps.miphone.aiai.app.AiAiPredictionService"); //第二种写法
ComponentName componentName=new ComponentName("com.google.android.as","com.google.android.apps.miphone.aiai.app.AiAiPredictionService");
intent.setComponent(componentName); startActivity(intent);
} /**
* 下面通过隐式意图来跳转到第三方应用
* 1、创建Intent对象
* 2、第二步给intent对象,设置Action、category,5.1以上要设置包名
* 3、startActivity(intent)
* @param view
*/
public void skip2BrowserInvisible(View view) {
Intent intent =new Intent();
intent.setAction("android.intent.action.SEARCH");
intent.addCategory("android.intent.category.DEFAULT");
intent.setPackage("com.google.android.as");
startActivity(intent);
} }

Activity组件(二):通过显式意图和隐式意图来跳转至第三方应用的更多相关文章

  1. Android 显示意图和隐式意图的区别

    意图在android的应用开发中是很重要的,明白了意图的作用和使用后,对开发会有很大帮助.如果没有把意图搞懂,以后开发应用会感觉缺些什么.        意图的作用:        1.激活组件   ...

  2. 转】C#接口-显式接口和隐式接口的实现

    [转]C#接口-显式接口和隐式接口的实现 C#中对于接口的实现方式有隐式接口和显式接口两种: 类和接口都能调用到,事实上这就是“隐式接口实现”. 那么“显示接口实现”是神马模样呢? interface ...

  3. selenium-webdriver中的显式等待与隐式等待

    在selenium-webdriver中等待的方式简单可以概括为三种: 1 导入time包,调用time.sleep()的方法传入时间,这种方式也叫强制等待,固定死等一个时间 2 隐式等待,直接调用i ...

  4. Java并发之显式锁和隐式锁的区别

    Java并发之显式锁和隐式锁的区别 在面试的过程中有可能会问到:在Java并发编程中,锁有两种实现:使用隐式锁和使用显示锁分别是什么?两者的区别是什么?所谓的显式锁和隐式锁的区别也就是说说Synchr ...

  5. C# Interface显式实现和隐式实现

    c#中对接口的实现方式有两种:隐式实现和显式实现,之前一直没仔细看过,今天查了些资料,在这里整理一下. 隐式实现的例子 interface IChinese { string Speak(); } p ...

  6. 多态设计 zen of python poem 显式而非隐式 延迟赋值

    总结 1.python支持延迟赋值,但是给调用者带来了困惑: 2.显式而非隐式,应当显式地指定要初始化的变量 class Card: def __init__(self, rank, suit): s ...

  7. C# 数据类型转换 显式转型、隐式转型、强制转型

    C# 的类型转换有 显式转型 和 隐式转型 两种方式. 显式转型:有可能引发异常.精确度丢失及其他问题的转换方式.需要使用手段进行转换操作. 隐式转型:不会改变原有数据精确度.引发异常,不会发生任何问 ...

  8. (java)selenium webdriver学习---三种等待时间方法:显式等待,隐式等待,强制等待

    selenium webdriver学习---三种等待时间方法:显式等待,隐式等待,强制等待 本例包括窗口最大化,刷新,切换到指定窗口,后退,前进,获取当前窗口url等操作: import java. ...

  9. Scala学习二十一——隐式转换和隐式参数

    一.本章要点 隐式转换用于类型之间的转换 必须引入隐式转换,并确保它们可以以单个标识符的形式出现在当前作用域 隐式参数列表会要求指定类型的对象.它们可以从当前作用域中以单个标识符定义的隐式对象的获取, ...

  10. Scala 中的隐式转换和隐式参数

    隐式定义是指编译器为了修正类型错误而允许插入到程序中的定义. 举例: 正常情况下"120"/12显然会报错,因为 String 类并没有实现 / 这个方法,我们无法去决定 Stri ...

随机推荐

  1. P1018 锤子剪刀布

    转跳点:

  2. 解决CGrIdCtrl合并单元格后继续拆分后的问题

    DWORD dwMergeCellCount = vMergeCells.size(); ; i < dwMergeCellCount; i++){ m_HFlexGrid.SplitCells ...

  3. 如何下载Github的工程到本地,完成修改并提交

    2019-02-22 对以下方法做了测试 可以生效 1 在Github上添加密钥 方法是:https://www.cnblogs.com/jason-beijing/p/9110187.html 2 ...

  4. Ubuntu 18.04 配置 adb

    Reference1:  https://www.jianshu.com/p/377c6fb6e590 Reference2:  https://blog.csdn.net/ppggxn/articl ...

  5. java登录以及连接数据库的温习

    学完一部分android相关知识点后,为了下周的java测试,我还是反回来重新的学习了上学期的知识点java,在今天打开eclipse之后,对于自己之前自己所写过的东西还有连接数据库的内容,已经有所忘 ...

  6. OnPaint中画图遇到的问题

    在OnPaint函数中有CPaintDC dc1(this);这句话,在画图时,千万不要把它去掉,否则会造成消息队列阻塞.例如定时器.Invalidate()等都会失效. 造成这种现象的原因是: CP ...

  7. zabbix_agent_win

    http://mayulin.blog.51cto.com/1628315/514447/ http://www.cnblogs.com/likehua/p/3968689.html 先下载win客户 ...

  8. SpringBoot之Order注解启动顺序

    order的规则: order的值越小,优先级越高order如果不标注数字,默认最低优先级,因为其默认值是int最大值该注解等同于实现Ordered接口getOrder方法,并返回数字. @Reten ...

  9. JAVA字节码文件之第四篇(方法分析)

    一.Methods 方法字节码结构 Methods 字节码结构: Methods num:占两byte,Methods 的具体内存占n个byte 方法中每个属性都是Attribute_info,Att ...

  10. SQL中的LEFT/RIGHT/SUBSTRING函数

    语法: LEFT(field,length) RIGHT(field,length)SUBSTRING(field,start,length) LEFT/RIGHT函数返回field最左边/最右边的l ...