打开网页

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)的更多相关文章

  1. android学习笔记29——Intent/IntentFilter

    Intent/IntentFilter Intent封装android应用程序需要启动某个组件的“意图”,Intent还是应用程序组件之间通信的重要媒介. EG:Activity之间需要交换数据时,使 ...

  2. Android学习笔记之Intent(1)

    1.Intent指定启动目标组件 2.Intentfilter描述基本组件所在地址 3.其他包引入资源文件时记得引入R所在的包 package com.jikexueyuan.intent; impo ...

  3. Android学习笔记之Intent

    Intent是Activity之间的管道 可以用来做Acitivity的跳转或传递数据 protected void onCreate(Bundle savedInstanceState) { sup ...

  4. 【转】Pro Android学习笔记(十二):了解Intent(下)

    解析Intent,寻找匹配Activity 如果给出component名字(包名.类名)是explicit intent,否则是implicit intent.对于explicit intent,关键 ...

  5. 【转】Pro Android学习笔记(十):了解Intent(上)

    目录(?)[-] Intent基本含义 系统的Intent Android引入了Intent的概念来唤起components,component包括:1.Activity(UI元件) 2.Servic ...

  6. Android学习笔记之Activity详解

    1 理解Activity Activity就是一个包含应用程序界面的窗口,是Android四大组件之一.一个应用程序可以包含零个或多个Activity.一个Activity的生命周期是指从屏幕上显示那 ...

  7. Pro Android学习笔记 ActionBar(1):Home图标区

     Pro Android学习笔记(四八):ActionBar(1):Home图标区 2013年03月10日 ⁄ 综合 ⁄ 共 3256字 ⁄ 字号 小 中 大 ⁄ 评论关闭 ActionBar在A ...

  8. 【转】Pro Android学习笔记(九八):BroadcastReceiver(2):接收器触发通知

    文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.sina.com.cn/flowingflying或作者@恺风Wei-傻瓜与非傻瓜 广播接 ...

  9. 【转】 Pro Android学习笔记(七七):服务(2):Local Service

    目录(?)[-] Local service代码 调用Local ServiceLocal Service client代码 AndroidManifestxml定义Serviceacitivty的l ...

随机推荐

  1. 自定义AccessDeniedHandler

    在Spring默认的AccessDeniedHandler中只有对页面请求的处理,而没有对Ajax的处理.而在项目开发是Ajax又是我们要常用的技术,所以我们可以通过自定义AccessDeniedHa ...

  2. Windows系统与Linux系统之间资源samba共享【转】

    配置SAMBA服务器来实现在Windows计算机与Linux计算机之间的用户级的资源共享,九河网络TOM[2694339173]教你怎样操作: SAMBA服务器的基本配置 配置SAMBA服务器来实现在 ...

  3. PHP数据库扩展mysqli的函数试题

    1.mysqli链接数据库的方式是什么? 2.mysqli获取链接错误号的属性是什么? 3.mysqli获取链接错误信息的属性是什么? 4.mysqli执行sql语句的函数是什么? 5.mysqli获 ...

  4. drupal7为admin/config页面添加自己开发的模块

    1.实现显示模块 //admin/config配置页面添加journal块 $items['admin/config/journal'] = array(//注意格式为'admin/config/模块 ...

  5. wpf计时器

    wpf应用程序间隔一段时间触发一个事件,代码如下: public MainWindow() { InitializeComponent(); DispatcherTimer timer = new D ...

  6. java中对List中对象排序实现

    package com.test; import java.util.ArrayList; import java.util.Collections; import java.util.Compara ...

  7. PL/SQL Developer StringBuffer 专用复制

    ;PL/SQL Developer SpecialCopy definition;<LINE_1> for first line;<LINE_*> for all other ...

  8. java 使用对象

    class XiyoujiRenwu { float height,weight; String head, ear; void speak(String s) { head="歪着头&qu ...

  9. UVALive 2522 Chocolate(概率DP)

    思路:定义DP方程dp[i][j]标记选到第i个巧克力的时候,桌面上还剩下j个巧克力,状态转移有两个方向,dp[i-1][j-1],dp[i-1]lj+1],分别表示桌面上多了一个和消了一个,乘上需要 ...

  10. CenOS配置VSFTP服务器

    1 Linux FTP服务器分类: wu-ftp proftp=profession ftp vsftp=very security ftp 2 安装vsftp yum install vsftp 3 ...