设置imageView的图像以联系照片

时间:2011-06-16 09:29:37

标签: android

想要从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)

我无法理解这个问题是什么 感谢

1 个答案:

答案 0 :(得分:0)

您是否有权更改联系信息?

 <uses-permission android:name="android.permission.WRITE_CONTACTS" />