0
想要設置來自imageView的照片來聯繫照片。 我想這一點,但我得到一個exception.Here是我的代碼:將imageView的圖片設置爲聯繫人照片
draw.btnSetAs.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Context context= getApplicationContext();
Bitmap icon= BitmapFactory.decodeResource(context.getResources(),
R.id.viwer_photo3);
try {
Intent myIntent = new Intent();
myIntent.setAction(ContactsContract.Intents.ATTACH_IMAGE);
myIntent.putExtra(Intent.EXTRA_STREAM, icon);
startActivity(myIntent);
} catch (ActivityNotFoundException anfe) {
Log.i("ImageContact",
"Firing Intent to set image as contact failed.", anfe);
}
}
});
我得到這個異常:
06-16 14:25:34.431: INFO/ImageContact(1708): Firing Intent to set image as contact failed.
06-16 14:25:34.431: INFO/ImageContact(1708): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.android.contacts.action.ATTACH_IMAGE (has extras) }
06-16 14:25:34.431: INFO/ImageContact(1708): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1567)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1537)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.app.Activity.startActivityForResult(Activity.java:2858)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.app.Activity.startActivity(Activity.java:2964)
06-16 14:25:34.431: INFO/ImageContact(1708): at com.aragast.display.FullScreenImageActivity$4.onClick(FullScreenImageActivity.java:143)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.view.View.performClick(View.java:2408)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.view.View$PerformClick.run(View.java:8817)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.os.Handler.handleCallback(Handler.java:587)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.os.Handler.dispatchMessage(Handler.java:92)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.os.Looper.loop(Looper.java:144)
06-16 14:25:34.431: INFO/ImageContact(1708): at android.app.ActivityThread.main(ActivityThread.java:4937)
06-16 14:25:34.431: INFO/ImageContact(1708): at java.lang.reflect.Method.invokeNative(Native Method)
06-16 14:25:34.431: INFO/ImageContact(1708): at java.lang.reflect.Method.invoke(Method.java:521)
06-16 14:25:34.431: INFO/ImageContact(1708): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-16 14:25:34.431: INFO/ImageContact(1708): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
而且我不明白什麼問題。
謝謝
我將此代碼添加到體現我得到相同的異常 – 2011-06-16 11:29:12
也許你還需要權限讀取聯繫人的信息後hadn't.But。 '<使用權限android:name =「android.permission.READ_CONTACTS」/>' – 2011-06-16 11:38:13
這是一個解決方案: 意圖myIntent = new Intent(); \t \t \t \t myIntent.setAction(Intent.ACTION_ATTACH_DATA); \t \t \t \t myIntent.setType(「image/jpeg」); \t \t \t \t myIntent.putExtra(Intent.EXTRA_STREAM,icon); \t \t \t \t startActivity(myIntent); – 2011-06-16 11:56:22