最近了解了一点关于Android 分享的东西 .
有 图片 ,字符串分享,我这里简单的汇总一下 ,希望可以在忘记的时间看一下.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Share Chooser"));
系统会自动调用手机上安装过的可以分享发送的APK,供选择.
分享单个文件,eg test.txt
File sendFile = new File(filePath + File.separator + FILENAME);
Intent share = new Intent(Intent.ACTION_SEND);
share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(sendFile));
share.setType("*/*");//
startActivity(Intent.createChooser(share, "Share"));
最后,还有一个调用自己写的activity,进行数据发送的(这里不写自己activity),只写intent.choose
File sendFile = new File(filePath + File.separator + FILENAME);
if (sendFile.exists()) {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("android.intent.action.XXMM");
intent.setDataAndType(Uri.parse(filePath + "test.txt"),
"mark/nimei");
startActivity(Intent.createChooser(intent, "Share Chooser"));
} else {
Toast.makeText(getApplicationContext(), "请确认是否有这个文件?",
Toast.LENGTH_SHORT).show();
}
下面是一个manifest中的一部分 ,调用的时间,intent 过滤
<!-- 下面的两个activity ,可以是自己写的 intent的 content , 通过intent 的方式 -->
<activity
android:name=".TestActivity"
android:label="你妹啊" >
<intent-filter>
<action android:name="android.intent.action.XXMM" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.OPENABLE" />
<data android:mimeType="mark/nimei" />
</intent-filter>
</activity>