调用android手机微博客户端发送微博
用隐式意图打开android手机中安装的微博客户端发送微博。
反编译一下新浪微博的AndroidManifest.xml,发送微博的EditActivity
<activity android:theme="@7F0C000B" android:label="@7F0B0013" android:name="EditActivity" android:taskAffinity="com.sina.weibo.newblog" android:configChanges="0x000000A0" android:windowSoftInputMode="0x00000010" > <intent-filter android:label="@7F0B00ED" > <action android:name="android.intent.action.SEND" > </action> <category android:name="android.intent.category.DEFAULT" > </category> <data android:mimeType="image/*" > </data> </intent-filter> <intent-filter android:label="@7F0B00ED" > <action android:name="android.intent.action.SEND" > </action> <data android:mimeType="text/plain" > </data> <category android:name="android.intent.category.DEFAULT" > </category> </intent-filter> <intent-filter android:label="@7F0B00ED" > <action android:name="com.sina.weibo.intent.action.NEW_BLOG" > </action> <category android:name="android.intent.category.DEFAULT" > </category> </intent-filter> </activity>
反编译一下新浪微博的EditActivity
EditActivity中的oncreate方法中重要代码
File localFile1 = Environment.getExternalStorageDirectory(); StringBuilder localStringBuilder = new StringBuilder("tmp_bmp_"); long l = SystemClock.currentThreadTimeMillis(); String str3 = l + ".jpg"; File localFile2 = new File(localFile1, str3); this.sdcardTempFile = localFile2; LauchMode localLauchMode = (LauchMode)getIntent().getSerializableExtra("com.sina.weibo.intent.extra.LAUCH_MODE"); onLauchModeChanged(localLauchMode);
private void onLauchModeChanged(LauchMode paramLauchMode) 如果我们用的是android.intent.action.SEND即LauchMode.SHARE;
if ((!sudroid.TextUtils.isEmptyOrBlank(str1)) && (str1.equals("android.intent.action.SEND"))) paramLauchMode = LauchMode.SHARE;
str2 = getIntent().getStringExtra("android.intent.extra.TEXT"); if (!android.text.TextUtils.isEmpty(str2)) { setEditText(str2); Editable localEditable = this.etMblog.getText(); int j = str2.length(); Selection.setSelection(localEditable, j); } loadShareImage();
文字信息已经在EditActivity中显示出来了 接下来要loadShareImage了
protected void loadShareImage() { Uri localUri = (Uri)getIntent().getParcelableExtra("android.intent.extra.STREAM"); if (localUri == null) return; displayImageUri(localUri); }
获取到Uri之后就要 displayImageUri
private void displayImageUri(Uri paramUri) { this.mImageLoadingHelper.importBitmapFile(paramUri); if (!this.mImageLoadingHelper.hasBitmap()) { Toast.makeText(this, 2131427539, 0).show(); return; } displayInsertBitmap(); }
如果Bitmap存在就displayInsertBitmap
Bitmap localBitmap = this.mImageLoadingHelper.createThumbnail(); localImageView1.setImageBitmap(localBitmap);
图片就展示在EditActivity中了
以上信息我们就可以写出调用EditActivity的隐式意图了。
Intent intent = new Intent("android.intent.action.SEND"); intent.setType("image/*"); intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); intent.putExtra(Intent.EXTRA_TEXT, "终于可以了!!!");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:////sdcard//8.png")); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(Intent.createChooser(intent, getTitle()));
当发送完微博后,我放到sdcard中的图片会消失。也就是这张图片//sdcard//8.png