intent传递有没有大小限制,是多少?- http://blog.csdn.net/wingichoy/article/details/50679322
Android Intent调用 Uri的使用几种格式- http://blog.csdn.net/bdmh/article/details/30491017
PendingIntent的FLAG_CANCEL_CURRENT和FLAG_UPDATE_CURRENT- http://blog.csdn.net/bdmh/article/details/41804695
Intent中显示意图和隐式意图的用法-- http://blog.csdn.net/loongggdroid/article/details/17887975
隐式Intent的用法- http://blog.51cto.com/ticktick/1621957
> Intent 能传递多大 Size 的数据?- https://mp.weixin.qq.com/s/v57mDRnSEZ6hl7-bc3ugwA
Intent 在 Activity 间传递基础类型数据或者可序列化的对象数据。但是 Intent 对数据大小是有限制的,当超过这个限制后,就会触发 TransactionTooLargeException 异常。
Intent 传输数据的机制中,用到了 Binder。Intent 中的数据,会作为 Parcel 被存储在 Binder 的事务缓冲区(Binder transaction buffer)中的对象进行传输。
而这个 Binder 事务缓冲区具有一个有限的固定大小,当前为 1MB。你可别以为传递 1MB 以下的数据就安全了,这里的 1MB 空间并不是当前操作独享的,而是由当前进程所共享。也就是说 Intent 在 Activity 间传输数据,本身也不适合传递太大的数据。
Intent 传输的数据,都存放在一个 Bundle 类型的对象 mExtras 中,Bundle 要求所有存储的数据,都是可被序列化的。
在 Android 中,序列化数据需要实现 Serializable 或者 Parcelable。对于基础数据类型的包装类,本身就是实现了 Serializable,而我们自定义的对象,按需实现这两个序列化接口的其中一个即可。
Activity 之间传递数据,首先要考虑跨进程的问题,而 Android 中又是通过 Binder 机制来解决跨进程通信的问题。涉及到跨进程,对于复杂数据就要涉及到序列化和反序列化的过程,这就注定是一次值传递(深拷贝)的过程。
Fragment 本身是不涉及跨进程的,这里虽然使用了 Bundle 传输数据,但是并没有通过 Binder,也就是不存在序列化和反序列化。和 Fragment 数据传递相关的 Bundle,其实传递的是原对象的引用。
既然原因在于 Binder 传输限制了数据的大小,那我们不走 Binder 通信就好了。
那就先看看这个图片的数据源。Drawable?本地文件?线上图片?无论数据源在哪里,我们只需要传递一个 drawable_id、路径、URL,就可以还原这张图片,无需将这个 Bitmap 对象传递过去。大数据总有数据源,从数据源还原数据,对我们而言只是调用一个方法而已。
阿里给出的方案,是通过 EventBus 来传递数据。很多商业项目其实都用到了 EventBus,这里就简单介绍如何使用 EventBus 的粘性事件来完成数据在 Activity 间的传递。
在 Activity 间,通过 Intent 传递大数据会触发 TransactionTooLargeException 异常的原因,以及如何解决它,最后再简单总结一下:
1.Intent 无法传递大数据是因为其内部使用了 Binder 通信机制,Binder 事务缓冲区限制了传递数据的大小。
2.Binder 事务缓冲区的大小限定在 1MB,但是这个尺寸是共享的,也就是并不是传递 1MB 以下的数据就绝对安全,要视当前的环境而定。
3.不要挑战 Intent 传递数据大小的极限,对于大数据,例如长字符串、Bitmap 等,不要考虑 Intent 传递数据的方案。
4.解决大数据传递问题,可以从数据源出发,根据数据的标识,还原数据,或者先持久化再还原。也可以使用 EventBus 的粘性事件来解决。
> Bundle与Intent机制
public final class Bundle extends BaseBundle implements Cloneable, Parcelable {}
由于实现了Cloneable和Parcelable接口,因此以下几个重载是必不可少的:
public Object clone()
public int describeContents()
public void writeToParcel(Parcel parcel, int flags)
public void readFromParcel(Parcel parcel)
public static final Parcelable.Creator
-- 为什么Android使用Bundle而不是HashMap?
1.Bundle内部是由ArrayMap实现的,ArrayMap的内部实现是两个数组,一个int数组是存储对象数据对应下标,一个对象数组保存key和value,内部使用二分法对key进行排序,所以在添加、删除、查找数据的时候,都会使用二分法查找,只适合于小数据量操作,如果在数据量比较大的情况下,那么它的性能将退化。而HashMap内部则是数组+链表结构,所以在数据量较少的时候,HashMap的Entry Array比ArrayMap占用更多的内存。因为使用Bundle的场景大多数为小数据量,我没见过在两个Activity之间传递10个以上数据的场景,所以相比之下,在这种情况下使用ArrayMap保存数据,在操作速度和内存占用上都具有优势,因此使用Bundle来传递数据,可以保证更快的速度和更少的内存占用。
2.另外一个原因,则是在Android中如果使用Intent来携带数据的话,需要数据是基本类型或者是可序列化类型,HashMap使用Serializable进行序列化,而Bundle则是使用Parcelable进行序列化。而在Android平台中,更推荐使用Parcelable实现序列化,虽然写法复杂,但是开销更小,所以为了更加快速的进行数据的序列化和反序列化,系统封装了Bundle类,方便我们进行数据的传输。
Bundle比较简单,只是一个数据容器,不像Activity等有复杂的生命周期。对于开发者来说,只需要了解Bundle的功能、使用场景并掌握常用的数据存取方法即可。
Bundle类用作携带数据,它类似于Map,用于存放key-value名值对形式的值,这里的mMap就是ArrayMap了,存储数据就是把键值对保存到ArrayMap里。 Intent旨在跳转和数据传递,bundle旨在存取数据,当然intent也提供一部分数据的存取.
Intent传递数据的大小是512K还是1M?
> Intent传递参数及参数序列化
1. 利用Intent对象携带简单数据
利用Intent的Extra部分来存储我们想要传递的数据,可以传送int, long, char等一些基础类型,对复杂的对象就无能为力了。
1.1 设置参数
//传递些简单的参数
Intent intentSimple = new Intent();
intentSimple.setClass(MainActivity.this,SimpleActivity.class);
Bundle bundleSimple = new Bundle();
bundleSimple.putString("usr", "xcl");
bundleSimple.putString("pwd", "zj");
intentSimple.putExtras(bundleSimple);
startActivity(intentSimple);
1.2 接收参数
this.setTitle("简单的参数传递例子");
//接收参数
Bundle bunde = this.getIntent().getExtras();
String eml = bunde.getString("usr");
String pwd = bunde.getString("pwd");
2. 利用Intent对象携带如ArrayList之类复杂些的数据
这种原理是和上面一种是一样的,只是要注意下。 在传参数前,要用新增加一个List将对象包起来。
2.1 设置参数
//传递复杂些的参数
Map
map1.put("key1", "value1");
map1.put("key2", "value2");
List
> Intent(意图),各种跳转
Android打开各种类型的文件方法总结- http://blog.csdn.net/eclipsexys/article/details/39552501
android调用系统功能-- http://blog.csdn.net/d945332077/article/details/8116326
android平台收发邮件-- http://blog.csdn.net/elena_wang/article/details/12648581
Intent(意图)主要是用于激活组件和解决Android应用的各项组件之间的通讯。
意图有分为显式意图和隐式意图。
public void showIntent(View view){ //显式意图
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
}
public void hideIntent(View view){ //隐式意图。
Intent intent = new Intent();
intent.setAction("com.pc.testintent.SecondActivity");
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
Intent解析机制主要是通过查找已注册在AndroidManifest.xml中的所有
application package的信息)来查找能处理这个Intent的component。在这个解析过程中,Android是通过Intent的action、type、category这三个属性来进行判断的,判断方法如下:
1.1 如果Intent指明定了action,则目标组件的IntentFilter的action列表中就必须包含有这个action,否则不能匹配;
1.2 如果Intent没有提供type,系统将从data中得到数据类型。和action一样,目标组件的数据类型列表中必须包含Intent的数据类型,否则不能匹配。
1.3 如果Intent中的数据不是content:类型的URI,而且Intent也没有明确指定type,将根据Intent中数据的scheme(比如 http:或者mailto:)进行匹配。同上,Intent 的scheme必须出现在目标组件的scheme列表中。
1.4 如果Intent指定了一个或多个category,这些类别必须全部出现在组建的类别列表中。比如Intent中包含了两个类别:LAUNCHER_CATEGORY和ALTERNATIVE_CATEGORY,解析得到的目标组件必须至少包含这两个类别。
> 打开Android手机安装的邮件客户端,可选择
Uri uri = Uri.parse("mailto:[email protected]");
Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
startActivity(Intent.createChooser(intent, "选择邮件客户端"));
> 邮件发送方式,其他文件打开方式-Intent的使用
android邮件发送几种方式--http://wcf1987.iteye.com/blog/1292509
Android邮件发送详解--http://blog.csdn.net/xanxus46/article/details/8296598/
【Android】发送Email(内置Gmail和JavaMail)--http://blog.csdn.net/lizhenmingdirk/article/details/7474918
android intent和intent action大全-- http://www.cnblogs.com/playing/archive/2010/09/15/1826918.html
Android开发之Intent.Action--http://www.cnblogs.com/hanyonglu/archive/2012/03/26/2417278.html
Android之调用系统Email发送邮件-- http://blog.csdn.net/way_ping_li/article/details/9038655
Android之Intent全面解析及用法--http://blog.csdn.net/cndrip/article/details/7191072
android上的默认Intent -- http://blog.csdn.net/xiaodanpeng/article/details/8282947
android intent打开各种文件的方法-- http://blog.csdn.net/wangyang2698341/article/details/20847469
Android 用Intent调用系统中经常被用到的组件-- http://www.cnblogs.com/zyw-205520/archive/2013/02/03/2890936.html
Android开发调用第三方邮件应用发送邮件-- http://blog.csdn.net/wangshihui512/article/details/51332744
> 通过Intent ACTION_SEND方法发送邮件,弹出的客户端选择
Java code
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "TEXT");
intent.setType("text/html");
startActivity(Intent.createChooser(intent, "Chooser"));
在出现的客户端选择中,只有Gmail和蓝牙,没有默认的Email客户端,这是为什么呢?
ACTION_SEND 这个方式就是用Gmail发送,而且不能指定用别的邮箱发送...
android发送邮件有两种方式,
一种就是你用的方法,用gmail,直接用intent来实现
另一种是用java的方式发送邮件,要设置pop,账户,密码等。。。
> 从浏览器跳转到app客户端
现在,用的方法是Response.Redirect("taobao://");(例如跳转到淘宝的客户端),在ios系统的浏览器上可以跳转到淘宝的客户端。但是在安卓系统的浏览器上,只是在当前浏览器上打开了淘宝客户端,而不是跳转到淘宝客户端。请问各位大神,该怎么解决呢?
------解决思路----------------------
java 与javaScript调用
------解决思路----------------------
Android提供了字符串形式的intent来解决这个问题,可以参考这篇文章。http://droidyue.com/blog/2014/11/23/start-android-application-when-click-a-link/
------解决思路----------------------
http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser
-------------------------------------------------------------------
> 打开默认浏览器
Intent intent =newIntent();
intent.setAction("android.intent.action.VIEW");
Uri content_url =Uri.parse("http://www.163.com");
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(intent);
只要修改以intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
中相应的应用程序packagename 和要启动的activity即可启动其他浏览器来
uc浏览器":"com.uc.browser", "com.uc.browser.ActivityUpdate“
opera浏览器:"com.opera.mini.android", "com.opera.mini.android.Browser"
qq浏览器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"
1. Intent open a picture file public:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new
File("/mnt/sdcard/images/001041580.jpg"));
intent.setDataAndType (uri, "image/*");
this.startActivity(intent);
2. Intent to open a PDF file:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new
File("file:///android_asset/helphelp.pdf"));
intent.setDataAndType (uri, "application/pdf");
this.startActivity(intent);
3. Intent to open a text file:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
if (paramBoolean){
Uri uri1 = Uri.parse (param);
intent.setDataAndType (URI1, "text/plain");
} else {
Uri uri = Uri.fromFile(new File("/mnt/sdcard/hello.txt"));
intent.setDataAndType (URI2, "text/plain");
}
this.startActivity(intent);
4. Intent to open the audio file:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra ("oneshot",0);
intent.putExtra ("configchange",0);
Uri uri = Uri.fromFile(new File("/mnt/sdcard/ren.mp3"));
intent.setDataAndType (uri, "audio/*");
this.startActivity(intent);
5. Intent to open the video file:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra ("oneshot",0);
intent.putExtra ("configchange",0);
Uri uri = Uri.fromFile(new File("/mnt/sdcard/ice.avi"));
intent.setDataAndType (uri, "video/*");
this.startActivity(intent);
6. Intent to open the CHM file:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File("/mnt/sdcard/ice.chm"));
intent.setDataAndType (uri, "application / x-chm");
this.startActivity(intent);
7. Intent to open a Word document:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File("/system/etc/help.doc"));
intent.setDataAndType(uri, "application/msword");
this.startActivity(intent);
8. Android Excel intent:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new File("/mnt/sdcard/Book1.xls"));
intent.setDataAndType (uri, "application/vnd.ms-excel");
this.startActivity(intent);
9. Intent to open the PPT file:
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(new
File("/mnt/sdcard/download/Android_PPT.ppt"));
intent.setDataAndType (uri, "application/vnd.ms-powerpoint");
this.startActivity(intent);
10. Display Html page::
Uri uri = Uri.parse ("http://www.google.com");
Intent intent = new Intent (Intent.ACTION_VIEW, uri);
this.startActivity(intent);
11. Show map:
Uri uri = Uri.parse ("geo: 38.899533, -77.036476");
Intent intent = new Intent (Intent.Action_VIEW, uri);
this.startActivity(intent);
12. Call the dialer:
Uri uri = Uri.parse ("tel: xxxxxx");
Intent intent = new Intent (Intent.ACTION_DIAL, uri);
this.startActivity(intent);
13. Call :
Uri uri = Uri.parse ("tel: xxxxxx");
Intent it = new Intent (Intent.ACTION_CALL, uri);
this.startActivity(intent);
/*permission:
14. Call to send text messages of the program :
Intent intent = new Intent (Intent.ACTION_VIEW);
intent.putExtra("sms_body","The SMS text");
intent.setType("vnd.android-dir/mms-sms");
this.startActivity(intent);
15. Send SMS :
Uri uri = Uri.parse("smsto:0800000123");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body","The SMS text");
this.startActivity(intent);
16. Send MMS :
Uri uri = Uri.parse("content://media/external/images/media/23");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body","some text");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
this.startActivity(intent);
17. Send an Email :
Uri uri = Uri.parse ("mailto: [email protected]");
Intent intent = new Intent (Intent.ACTION_SENDTO, uri);
this.startActivity(intent);
18. Send an Email with body :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL,"[email protected]");
intent.putExtra(Intent.EXTRA_TEXT,"The email body text");
intent.setType ("text/plain");
this.startActivity(
Intent.createChooser(intent, "Choose Email Client"));
19. Send an Email with body,to,cc :
Intent intent = new Intent(Intent.ACTION_SEND);
String [] tos ={"[email protected]"};
String [] ccs ={"[email protected]"};
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "The email body text");
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
intent.setType("message/rfc822");
this.startActivity(
Intent.createChooser(intent, "Choose Email Client"));
20. Send an Email with attachments :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT,"The email subject text");
intent.putExtra(Intent.EXTRA_STREAM,"file :///sdcard/mysong.mp3");
sendIntent.setType("audio/mp3");
this.startActivity(
Intent.createChooser(intent,"Choose Email Client"));
21. Uninstall the program :
Uri uri = Uri.fromParts ("package", strPackageName,null);
Intent intent = new Intent (Intent.ACTION_DELETE, uri);
this.startActivity(
Intent.createChooser(intent,"Choose Email Client"));
22. Install the apk :
Uri installUri = Uri.fromParts("package","xxx", null);
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);
this.startActivity(returnIt);
23. Search applications :
Uri uri = Uri.parse("market://search?Q=pname:pkg_name");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
this.startActivity(intent);
//Where pkg_name is the full package path for an application
24. Google Search Launch Web Browser :
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = "Android";
intent.putExtra(SearchManager.QUERY, term);
activity.startActivity(intent);
25. Send text using Intent (to messaging apps) :
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String msgBody = "This is message";
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"message subject");
intent.putExtra(android.content.Intent.EXTRA_TEXT, msgBody);
activity.startActivity(Intent.createChooser(intent, getResources().
getString(R.string.share_by_using)));
26. Create Shortcut on "Home Screen" :
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
Intent toPrint = new Intent(this, anCreateshutcut.class);
Intent addShortcut = new Intent
("com.android.launcher.action.INSTALL_SHORTCUT");
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shutcutname");
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, toPrint);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
Manifest file:
27. 18身份证号码校验
18身份证号码的结构-公民身份号码是特征组合码,由十七位数字本体码和一位校验码组成。排列顺序从左至右依次为:六位数字地址码,八位数字出生日期码,三位数字顺序码和一位校验码。
(1)十七位数字本体码加权求和公式
S = Sum(Ai * Wi), i = 0, … , 16 ,先对前17位数字的权求和
Ai:表示第i位置上的身份证号码数字值(0~9)
Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 (表示第i位置上的加权因子)
(2)计算模 Y = mod(S, 11)
(3)根据模,查找得到对应的校验码 Y: 0 1 2 3 4 5 6 7 8 9 10 校验码: 1 0 X 9 8 7 6 5 4 3 2
根据17位数字本体码获取最后一位校验码程序实例
public class Id18 {
int[] weight={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; //十七位数字本体码权重
char[] validate={ '1','0','X','9','8','7','6','5','4','3','2'}; //mod11,对应校验码字符值
public char getValidateCode(String id17){
int sum = 0;
int mode = 0;
for(int i = 0; i < id17.length(); i++){
sum=sum+Integer.parseInt(String.valueOf(id17.charAt(i)))*weight[i];
}
mode = sum % 11;
return validate[mode];
}
public static void main(String[] args){
Id18 tes t= new Id18();
System.out.println("该身份证验证码:"+test.getValidateCode("14230219700101101")); //该身份证校验码:3
}
}