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 ...
随机推荐
- Ubuntu 网管服务器配置
1.设置Linux内核支持ip数据包的转发 echo "1" > /proc/sys/net/ipv4/ip_forward or vi /etc/sysctl.conf ...
- Docker私有仓库Registry 搭建
1. 关于Registry 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候,我们的使用场景需要我们拥有一个私有 ...
- win10快捷键大全
win10快捷键大全大家可以来了解一下,今天小编带来了win10常用快捷键,很多朋友喜欢使用快捷键来操作电脑,那么Windows10系统有哪些新的快捷键呢• 贴靠窗口:Win +左/右> Win ...
- pulseaudio的交叉编译
在/etc/profile里导入 export PATH==$PATH:/home/jack/arm-linux-gcc/x-tools/arm-unknown-linux-gnueabi/bin 配 ...
- maven source
accepted To download sources for your dependencies: mvn eclipse:eclipse -DdownloadSources=true To at ...
- wpf中ListBox的选中项与ComboBox间的绑定
产品类: public class Product:NotificationObject { private int productID; public int ProductID { get { r ...
- 【中国剩余定理】 poj 1006
生理周期 简单模拟 对于超出23 * 28 * 33(21252)时进行求余运算即可. #include<stdio.h> int main() { //freopen("in ...
- [DP]一道理想收入问题【转】
题意:以一元为本金,能获得的最大收入,第i天股票价格为v[i],1<=i<=m 思路: (1)DP思路明显,直接进行动态规划,令f[i]代表第i天所获得的最大收入.那么有公式: f[i] ...
- Day02——widow对象
window - 计时器 1、setTimeout()可以用来在指定的时间之后单次调用函数. setTimeount(f,1000);//一秒后调用函数f clearTimeout();取消函数的执行 ...
- Spring Boot 系列教程12-EasyPoi导出Excel下载
Java操作excel框架 Java Excel俗称jxl,可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件,现在基本没有更新了 http://jxl.sourcef ...