您的位置:首页 > 移动开发 > Android开发

Android手机应用接口大全

2016-07-11 20:58 519 查看

Android手机应用接口大全

AndroidSocketGoogleCC++ 

显示网页:

  1. Uri uri = Uri.parse("http://www.google.com");

  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);

  3. startActivity(it);

显示地图:

  1. Uri uri = Uri.parse("geo:38.899533,-77.036476");

  2. Intent it = new Intent(Intent.Action_VIEW,uri);

  3. startActivity(it);

路径规划:

  1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");

  2. Intent it = new Intent(Intent.ACTION_VIEW,URI);

  3. startActivity(it);

拨打电话:

调用拨号程序

  1. Uri uri = Uri.parse("tel:xxxxxx");

  2. Intent it = new Intent(Intent.ACTION_DIAL, uri);  

  3. startActivity(it);  

  1. Uri uri = Uri.parse("tel.xxxxxx");

  2. Intent it =new Intent(Intent.ACTION_CALL,uri);

  3. 要使用这个必须在配置文件中加入<uses-permission id="android.permission.CALL_PHONE" />

发送SMS/MMS

调用发送短信的程序

  1. Intent it = new Intent(Intent.ACTION_VIEW);

  2. it.putExtra("sms_body", "The SMS text");

  3. it.setType("vnd.android-dir/mms-sms");

  4. startActivity(it);  

发送短信

  1. Uri uri = Uri.parse("smsto:0800000123");

  2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  3. it.putExtra("sms_body", "The SMS text");

  4. startActivity(it);  

发送彩信

  1. Uri uri = Uri.parse("content://media/external/images/media/23");

  2. Intent it = new Intent(Intent.ACTION_SEND);

  3. it.putExtra("sms_body", "some text");

  4. it.putExtra(Intent.EXTRA_STREAM, uri);

  5. it.setType("image/png");

  6. startActivity(it);

发送Email

  1.

  2. Uri uri = Uri.parse("mailto:xxx@abc.com");

  3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  4. startActivity(it);

  1. Intent it = new Intent(Intent.ACTION_SEND);

  2. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");

  3. it.putExtra(Intent.EXTRA_TEXT, "The email body text");

  4. it.setType("text/plain");

  5. startActivity(Intent.createChooser(it, "Choose Email Client"));  

  1. Intent it=new Intent(Intent.ACTION_SEND);  

  2. String[] tos={"me@abc.com"};  

  3. String[] ccs={"you@abc.com"};  

  4. it.putExtra(Intent.EXTRA_EMAIL, tos);  

  5. it.putExtra(Intent.EXTRA_CC, ccs);  

  6. it.putExtra(Intent.EXTRA_TEXT, "The email body text");  

  7. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

  8. it.setType("message/rfc822");  

  9. startActivity(Intent.createChooser(it, "Choose Email Client"));

添加附件

  1. Intent it = new Intent(Intent.ACTION_SEND);

  2. it.putExtra(Intent.EXTRA_SUBJECT, "The emai
4000
l subject text");

  3. it.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");

  4. sendIntent.setType("audio/mp3");

  5. startActivity(Intent.createChooser(it, "Choose Email Client"));

播放多媒体

  1.  

  2. Intent it = new Intent(Intent.ACTION_VIEW);

  3. Uri uri = Uri.parse("file:///sdcard/song.mp3");

  4. it.setDataAndType(uri, "audio/mp3");

  5. startActivity(it);

  1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");

  2. Intent it = new Intent(Intent.ACTION_VIEW, uri);

  3. startActivity(it);  

Uninstall 程序

  1. Uri uri = Uri.fromParts("package", strPackageName, null);

  2. Intent it = new Intent(Intent.ACTION_DELETE, uri);

  3. startActivity(it);

Android 源码分析-打电话和发短信

  1. ITelephony接口和ISms接口以及AIDL

 在我们的Android应用中,当需要实现电话拨号时,我们需要进行如下调用

 ITelephony phone = (ITelephony)ITelephony.Stub.asInterface(ServiceManager.getService("phon"))

 phone.dial("10086");

   对于短信应用,我们需要的是调用SmsManager,代码如下

   SmsManager manager = SmsManager.getDefault();

   manager.sendTextMessage("10086",null,"hi,this is sms",null,null);

   这里,SmsManager对ISms做了一层包装,实质上是通过调用

   ISms simISms = ISms.Stub.asInterface(ServiceManager.getService("isms"));

   simISms.sendRawPdu....

  

  可以看到,应用都是采用AIDL来实现IPC的跨进程调度。

  对于AIDL应用,调用进程方存在的是一个实现接口的Proxy对象,通过Proxy对象与被调用进程中的Stub对象进行

  通讯来实现IPC的跨进程调度,所以,在被调用进程一端必定有一个ITelephony.Stub类以及ISms.Stub类的实现。

  2. PhoneInterfaceManager和SimSmsInterfaceManager

   ITelephony.Stub 的实现类为com.android.phone.PhoneInterfaceManager

   ISms.Stub的实现类为com.android.internal.telephony.gsm.SimSmsInterfaceManager

   从这两个类的构造器的调用代码里可以很清楚的看到进行了Service的注册工作

   ServiceManager.addService("phone",this);

   ServiceManager.addService("isms",this);

  3. PhoneApp,InCallScreen,PhoneUtils及其他相关类

  从SimSmsInteferManager的相关方法实现中可以看到,具体就是调用GSMPhone的SmsDispatcher实例来进行相关操作的。

  从PhoneInterfaceManager会维持一个Phone对象的引用,当拨号应用时,PhoneInterfaceManager会将构造好的Intent传递

给PhoneApp应用,该Intent的className指定则为InCallScreen,从中我们可以看到InCallScreen具体是通过PhoneUtils调用Phone的

相关方法来实现。

  PhoneInterfaceManager怎么获取到对应的Phone对象,然后又怎么将Phone对象传递到InCallScreen中呢?

  具体这里涉及到了PhoneApp这个类,从这个类维护了一个 PhoneInterfaceManager的引用(phoneMgr)以及一个Phone引用(phone),

从该类的onCreate方法中我们可以清楚的看到,PhoneApp通过PhoneFactory获取了一个Phone实例,并通过该实例实现了PhoneInterfaceManager对象。

因此,我们现在只需要关注PhoneFactory具体提供的是一个什么样的Phone实例了。

  另外,PhoneApp类还提供了一个静态方法getInstance供InCallScreen调用,InCallScreen正是通过调用该方法获得PhoneApp实例从而

获得对应的Phone实例的。

  接下来,我们通过查看PhoneFactory的方法可以看到,Phone对象对应的就是一个GSMPhone实例。

  4。GSMPhone与RIL

  从GSM的构造器可以看出,他依赖一个CommandInterface接口实例,通过PhoneFactory的makeDefaultPhones方法,我们可以看到,根据系统环境变量

ro.radio.noril来判断是否需要采用RIL框架实现,如果该参数不为空,则采用Simultedcommands(主要是为了测试需要提供的模拟实现).否则,采用RIL。

  通过Google才知道,RIL其实是智能手机上实现AP与BP之间通信的一种设计思想,具体大家可以参见这篇文章http://www.eetchina.com/ARTICLES ... DF?SOURCES=DOWNLOAD

  在RIL.java 中我们很惊喜的看到,RIL对对消息的处理是将消息通过LocalSocket发送到以rild为名称的有名端口。这个有名Socket的创建在ril.cpp代码中。

  s_fdListen = android_get_control_socket(SOCKET_NAME_RIL)

  原来Android通话和发短信的应用是JAVA与C++代码之间透过Socket连接来传输消息来实现的。

  5.关于C代码与硬件之间的交互

  这部分工作其实就是C代码通过串口发送AT指令来拨号,收发短信。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: