Android学习笔记之Intent(2)
打开网页
package com.jiahemeikang.helloandroid; import java.io.File; import com.jiahemikang.service.EchoService;
import com.jiahemikang.service.EchoService.EchoServiceBingder;
import com.jikexuyua.broadcastreceiver.MyBC; import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.ContactsContract;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView; public class MainActivity extends Activity implements OnClickListener,ServiceConnection{ private TextView tvResult ;
private Intent serviceIntent;
private Button btnStarAty1;
private Button btnStarService;
private Button btnStopService;
private Button btnAction;
private Button btnBingService;
private Button btnUnBingService;
private Button btnGetNum;
private Button btnbroadcast;
private Button regbroadcastButton;
private Button btnOpenPic;
private Button btnOpenUrl;
private Button btnunregbroadcastButton;
public EchoService echoService = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
serviceIntent = new Intent(this,EchoService.class);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvResult = (TextView)findViewById(R.id.tvResult); btnStarAty1= (Button)findViewById(R.id.btnStartAty1);
btnStarService= (Button)findViewById(R.id.btnStartService);
btnStopService= (Button)findViewById(R.id.btnStopService); btnOpenPic= (Button)findViewById(R.id.btnOpenPic);
btnOpenPic.setOnClickListener(this);
btnOpenUrl= (Button)findViewById(R.id.btnOpenUrl);
btnOpenUrl.setOnClickListener(this); btnStarService.setOnClickListener(this);
btnStopService.setOnClickListener(this); btnBingService= (Button)findViewById(R.id.bingdingservice);
btnUnBingService= (Button)findViewById(R.id.unbingdingservice);
btnBingService.setOnClickListener(this);
btnUnBingService.setOnClickListener(this); btnGetNum= (Button)findViewById(R.id.btnGetNum);
btnGetNum.setOnClickListener(this); btnbroadcast= (Button)findViewById(R.id.btnbroadcast);
btnbroadcast.setOnClickListener(this); btnAction= (Button)findViewById(R.id.btnAction);
btnAction.setOnClickListener(this); regbroadcastButton= (Button)findViewById(R.id.btnregbroadcast);
regbroadcastButton.setOnClickListener(this);
btnunregbroadcastButton= (Button)findViewById(R.id.btnunregbroadcast);
btnunregbroadcastButton.setOnClickListener(this); btnStarAty1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){ Intent i = new Intent(MainActivity.this,Aty1.class);
i.putExtra("txt","Hello aty1");
startActivity(i);
startActivityForResult(i,0);
}
});
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while (cursor.moveToNext()) {
String _strName =cursor.getString(cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
System.out.println(">>>>>>>>>>>>>>>"+_strName);
}
} @Override
protected void onActivityResult(int a,int b ,Intent i){ if (i!=null) {
String result = i.getStringExtra("result"); tvResult.setText(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} private final MyBC myBC = new MyBC();
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btnStartService:
startService(serviceIntent);
break;
case R.id.btnStopService:
stopService(serviceIntent);
break;
case R.id.bingdingservice:
bindService(serviceIntent,this,Context.BIND_AUTO_CREATE);
break;
case R.id.unbingdingservice:
unbindService(this);
echoService =null;
break;
case R.id.btnGetNum:
if (echoService!=null) {
System.out.print("当前服务的 数字为"+echoService.getCountNum());
}
break;
case R.id.btnbroadcast:
Intent i = new Intent(MyBC.ACTION);
i.putExtra("txt", "消息");
sendBroadcast(i);
break;
case R.id.btnregbroadcast:
registerReceiver(myBC, new IntentFilter(MyBC.ACTION));
break;
case R.id.btnunregbroadcast:
unregisterReceiver(myBC);
break;
case R.id.btnAction:
Intent ii = new Intent("com.jikexueyuan.intent.action.Aty2");
startActivity(ii);
break;//btnOpenUrl
case R.id.btnOpenPic:
File file = new File("/mnt/sdcard/1.jpg");
Intent intentfile = new Intent(Intent.ACTION_VIEW);
intentfile.setDataAndType(Uri.fromFile(file), "image/*");
startActivity(intentfile);
break;
case R.id.btnOpenUrl:
System.out.print("打开网页.........");
Intent intenturl = new Intent(Intent.ACTION_VIEW,Uri.parse("https://www.hao123.com/"));
startActivity(intenturl);
break;
default:
break;
}
} @Override
public void onServiceConnected(ComponentName arg0, IBinder binder) {
System.out.println("onServiceConnected");
echoService = ((EchoService.EchoServiceBingder)binder).getService(); } @Override
public void onServiceDisconnected(ComponentName arg0) {
// TODO Auto-generated method stub } //onStart }
Android学习笔记之Intent(2)的更多相关文章
- android学习笔记29——Intent/IntentFilter
Intent/IntentFilter Intent封装android应用程序需要启动某个组件的“意图”,Intent还是应用程序组件之间通信的重要媒介. EG:Activity之间需要交换数据时,使 ...
- Android学习笔记之Intent(1)
1.Intent指定启动目标组件 2.Intentfilter描述基本组件所在地址 3.其他包引入资源文件时记得引入R所在的包 package com.jikexueyuan.intent; impo ...
- Android学习笔记之Intent
Intent是Activity之间的管道 可以用来做Acitivity的跳转或传递数据 protected void onCreate(Bundle savedInstanceState) { sup ...
- 【转】Pro Android学习笔记(十二):了解Intent(下)
解析Intent,寻找匹配Activity 如果给出component名字(包名.类名)是explicit intent,否则是implicit intent.对于explicit intent,关键 ...
- 【转】Pro Android学习笔记(十):了解Intent(上)
目录(?)[-] Intent基本含义 系统的Intent Android引入了Intent的概念来唤起components,component包括:1.Activity(UI元件) 2.Servic ...
- Android学习笔记之Activity详解
1 理解Activity Activity就是一个包含应用程序界面的窗口,是Android四大组件之一.一个应用程序可以包含零个或多个Activity.一个Activity的生命周期是指从屏幕上显示那 ...
- Pro Android学习笔记 ActionBar(1):Home图标区
Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...
- 【转】Pro Android学习笔记(九八):BroadcastReceiver(2):接收器触发通知
文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.sina.com.cn/flowingflying或作者@恺风Wei-傻瓜与非傻瓜 广播接 ...
- 【转】 Pro Android学习笔记(七七):服务(2):Local Service
目录(?)[-] Local service代码 调用Local ServiceLocal Service client代码 AndroidManifestxml定义Serviceacitivty的l ...
随机推荐
- iOS 最值宏定义
NSIntegerMax.NSIntegerMin.NSUIntegerMax.MAXFLOAT
- Mybatis——helloWorld级程序
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC & ...
- Windows 常用消息及含义
消息范围 说明 0 - WM_USER – 1 系统消息 WM_USER - 0x7FFF 自定义窗口类整数消息 WM_APP - 0xBFFF 应用程序自定义消息 0xC000 - 0xFFFF ...
- jQuery仿百度帖吧头部固定不随滚动条滚动效果
<style> *{margin:0px;padding:0px;} div.nav{background:#000000;height:57px;line-height:57px;col ...
- UIGestureRecognizer 手势浅析
目录[-] iOS开发中的手势体系——UIGestureRecognizer分析及其子类的使用 一.引言 二.手势的抽象类——UIGestureRecognizer 1.统一的初始化方法 2.手势状态 ...
- ubuntu环境下安装Tomcat
tomcat 是javaweb开发的本地服务器,tomcat是目前比较流行的一款. 1.下载Tomcat:http://tomcat.apache.org 2.进入下载文件夹解压Tomcat:sudo ...
- android 5.0新特性学习--CardView
CardView继承自FrameLayout类,可以在一个卡片布局中一致性的显示内容,卡片可以包含圆角和阴影.CardView是一个Layout,可以布局其他View. 官网地址:https://de ...
- Telepro工具注册码
Teleport Pro v1.54 注册码 Teleport Pro v1.54姓名(Name):3ddown.com序列号(Serial):161594593
- Chapter 1 First Sight——21
They were sitting in the corner of the cafeteria, as far away from where I sat as possible in the lo ...
- Android Studio的使用(十)--读取assets、Raw文件夹下文件,以及menu、drawable文件夹
1.直接在/src/main目录下面新建assets目录 2.接下来即可读取文件 3.读取Raw文件夹下文件也类似.首先在res文件夹下新建raw目录,然后放入需要的文件即可读取. 4.menu和dr ...