隐式Intent跳转

在Intent中明确表明跳转界面的为显式跳转,还有另一种跳转为隐式跳转,即为不明确表明跳转界面。

首先,在Activity中建立几个Button,分别实现拨打电话,发送短信,打开网页,播放音乐,视频,打开图片,安装APK,添加通知栏。在实现上述功能后,点击Activity中的图片,弹出PopWindow,PopWindow中有相册,相机,退出按钮,点击相册更经过裁剪后换图片,点击相机经过裁剪后更换,点击退出返回Activity界面

1、在清单文件中添加用户权限,

<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
在Activity中使用的是布局监听,


public class IntentActivity extends AppCompatActivity implements View.OnClickListener{
    private View view;
    private RoundImageView riv;             //圆形图片
    private PopupWindow pw;                 //全局PopWindow


protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_intent);
        pw = new PopupWindow(view);                      
        Button bt1= (Button) findViewById(R.id.bt1);     //找到Button
        Button bt2= (Button) findViewById(R.id.bt2);
        Button bt3= (Button) findViewById(R.id.bt3);
        Button bt4= (Button) findViewById(R.id.bt4);
        Button bt5= (Button) findViewById(R.id.bt5);
        Button bt6= (Button) findViewById(R.id.bt6);
        Button bt7= (Button) findViewById(R.id.bt7);
        Button bt8= (Button) findViewById(R.id.bt8);  
        riv= (RoundImageView) findViewById(R.id.riv);           
        view=getLayoutInflater().inflate(R.layout.pop_layout, null); //得到PopWindow布局
        Button img= (Button) view.findViewById(R.id.img);
        Button cream= (Button) view.findViewById(R.id.cream);
        Button exit= (Button) view.findViewById(R.id.exit);
        bt1.setOnClickListener(this);                             //设置监听事件
        bt2.setOnClickListener(this);
        bt3.setOnClickListener(this);
        bt4.setOnClickListener(this);
        bt5.setOnClickListener(this);
        bt6.setOnClickListener(this);
        bt7.setOnClickListener(this);
        bt8.setOnClickListener(this);
        img.setOnClickListener(this);
        cream.setOnClickListener(this);
        exit.setOnClickListener(this);
        riv.setOnClickListener(this);

    }
}
  布局代码如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"  //布局中被注释掉的部分为测试PopWindow使用
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.administrator.intent.IntentActivity">

   <Button
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/bt1"
       android:text="拨打电话"
       android:layout_alignParentTop="true"
       android:layout_alignParentStart="true" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bt2"
        android:text="短信"
        android:layout_below="@+id/bt1"
        android:layout_alignParentStart="true" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bt3"
        android:text="网页"
        android:layout_below="@+id/bt2"
        android:layout_alignParentEnd="true" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bt4"
        android:text="播放音乐"
        android:layout_below="@+id/bt3"
        android:layout_alignParentStart="true" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bt5"
        android:text="视频"
        android:layout_below="@+id/bt4"
        android:layout_alignParentEnd="true" />
    <!--<Button-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:text="图片"-->
        <!--android:id="@+id/bt6"-->
        <!--android:layout_below="@+id/bt5"-->
        <!--android:layout_alignParentEnd="true"-->
        <!--android:layout_marginTop="43dp" />-->
    <!--<Button-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:text="安装APK"-->
        <!--android:id="@+id/bt7"-->
        <!--android:layout_alignParentEnd="true"-->
        <!--android:layout_below="@+id/bt6" />-->
    <!--<Button-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:id="@+id/bt8"-->
        <!--android:text="通知拦"-->
        <!--android:layout_below="@+id/bt7"-->
        <!--android:layout_alignParentStart="true" />-->
    <com.example.administrator.intent.RoundImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/riv"

        android:src="@mipmap/image3"
        android:layout_below="@+id/bt5"
        android:layout_alignParentStart="true" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"
        android:layout_alignTop="@+id/riv"
        android:layout_toEndOf="@+id/riv"
        android:layout_marginStart="40dp" />
</RelativeLayout>
 
 
 
@Override
     public void onClick(View v) {
        int id= v.getId();

         switch(id){
            case R.id.bt1:
                Uri uri=Uri.parse("tel:10086");
                Intent intent =new Intent(Intent.ACTION_DIAL,uri);
                startActivity(intent);
                break;
             case R.id.bt2:
                 Intent it2=new Intent(Intent.ACTION_VIEW);
                 it2.putExtra("sms_body","你好");
                 it2.setType("vnd.android-dir/mms-sms");
                 startActivity(it2);
                 break;

             case R.id.bt3:
                 Uri uri1=Uri.parse("http://www.baidu.com");
                 Intent it3=new Intent(Intent.ACTION_VIEW,uri1);
                 startActivity(it3);
                 break;
             case  R.id.bt4:
                 Intent it4 =new Intent(Intent.ACTION_VIEW);
                 File file =new File("");
                 it4.setDataAndType(Uri.fromFile(file), "audio/*");
                 startActivity(it4);
                 break;
             case R.id.bt5:
                 Intent it5 =new Intent(Intent.ACTION_VIEW);
                 File file1=new File("");
                 it5.setDataAndType(Uri.fromFile(file1),"video/*");
                 startActivity(it5);
                 break;

//             case R.id.bt6:
//                 Intent it6 =new Intent(Intent.ACTION_VIEW);
//                 File file2=new File("");
//                 it6.setDataAndType(Uri.fromFile(file2),"image/*");
//                 startActivity(it6);
//                 break;
//
//             case R.id.bt7:
//                 Intent it7=new Intent(Intent.ACTION_VIEW);
//                 it7.setDataAndType(Uri.parse("file:///sdcard/qq.apk"),
//                         "application/vnd.android.package-archive");
//                 startActivity(it7);
//                 break;
//             case R.id.bt8:
//                 notification();
//                 break;
             case R.id.riv:
                 pw.setFocusable(true);                 //设置点击页面其他位置可退出
                 pw.setAnimationStyle(R.style.popStyle); //在drawable中建立anim文件夹,存放动画进入,退出效果
                 backgroundAlpha(0.3f);                   //
                 ColorDrawable cd = new ColorDrawable();
                 pw.setBackgroundDrawable(cd);
                 Log.d("===", "111111");
                 int width=getResources().getDisplayMetrics().widthPixels;
                 pw.setWidth(width);
                 int height = getResources().getDisplayMetrics().heightPixels/4;
                 pw.setHeight(height);
                 pw.showAtLocation(findViewById(R.id.bt1), Gravity.BOTTOM | Gravity.CENTER, 0, 0);
                 pw.setOnDismissListener(new PopupWindow.OnDismissListener() {
                     @Override
                     public void onDismiss() {
                         backgroundAlpha(1.0f);
                     }
                 });
                 break;
             case R.id.exit:
                  Log.d("===", "asddd");
                  pw.dismiss();
                  break;
             case R.id.img:
                 photoPhoto();
                   break;
             case R.id.cream:
                 tekePhoto();
                 break;

         }

     }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值