我试图从以下链接运行PhotoStream示例
http://android-developers.blogspot.com/2008/09/android-photostream.html
但是,当我尝试设置图像的壁纸(参考类ViewPhotoActivity.java)时,我得到以下错误
Run Code Online (Sandbox Code Playgroud)android.content.ActivityNotFoundException:无法找到显式活动类{com.android.camera/com.android.camera.CropImage}; 你有没有在AndroidManifest.xml中声明这个活动?
我认为以下代码导致了问题
final Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.camera", "com.android.camera.CropImage");
intent.setData(Uri.fromFile(mFile));
intent.putExtra("outputX", width);
intent.putExtra("outputY", height);
intent.putExtra("aspectX", width);
intent.putExtra("aspectY", height);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra("output", Uri.parse("file:/" + mFile.getAbsolutePath()));
startActivityForResult(intent, REQUEST_CROP_IMAGE);
Run Code Online (Sandbox Code Playgroud)
当我试图找到这个问题的解决方案,但没有得到任何.
小智 19
实际上有很多应用程序,它们在Android 2.x中提供CROP动作:标准图库,或Flikie壁纸,仅举几个例子.为什么成功解决意图失败的原因是Google改变了提供API的组件.在Android 1.x中可能是com.android.gallery,但是从(我认为)API9/Android 2.3.x开始,默认的库是由Cooliris提供的,所以它就像com.cooliris.gallery等.
在任何手机上解决意图的正确方法是(我使用的代码):
// this is something to keep our information
class CropOption
{
CharSequence TITLE;
Drawable ICON;
Intent CROP_APP;
}
// we will present the available selection in a list dialog, so we need an adapter
class CropOptionAdapter extends ArrayAdapter<CropOption>
{
private List<CropOption> _items;
private Context _ctx;
CropOptionAdapter(Context ctx, List<CropOption> items)
{
super(ctx, R.layout.crop_option, items);
_items = items;
_ctx = ctx;
}
@Override
public View getView( int position, View convertView, ViewGroup parent )
{
if ( convertView == null )
convertView = LayoutInflater.from( _ctx ).inflate( R.layout.crop_option, null );
CropOption item = _items.get( position );
if ( item != null )
{
( ( ImageView ) convertView.findViewById( R.id.crop_icon ) ).setImageDrawable( item.ICON );
( ( TextView ) convertView.findViewById( R.id.crop_name ) ).setText( item.TITLE );
return convertView;
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
项目的布局应该是带有IconView和TextView的水平线性布局.为了简洁起见,我会跳过它,现在你很可能知道怎么做了:-)
现在,对于我们找到意图并将它们呈现给选择的部分(这只是函数的相关部分,onActivityResult):
try
{
final List<CropOption> cropOptions = new ArrayList<CropOption>();
// this 2 lines are all you need to find the intent!!!
Intent intent = new Intent( "com.android.camera.action.CROP" );
intent.setType( "image/*" );
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
if ( list.size() == 0 )
{
// I tend to put any kind of text to be presented to the user as a resource for easier translation (if it ever comes to that...)
Toast.makeText( this, getText( R.string.error_crop_option ), Toast.LENGTH_LONG );
// this is the URI returned from the camera, it could be a file or a content URI, the crop app will take any
_captureUri = null; // leave the picture there
break; // leave this switch case...
}
intent.setData( _captureUri );
intent.putExtra( "outputX", 128 );
intent.putExtra( "outputY", 128 );
intent.putExtra( "aspectX", 1 );
intent.putExtra( "aspectY", 1 );
intent.putExtra( "scale", true );
//intent.putExtra( "", true ); // I seem to have lost the option to have the crop app auto rotate the image, any takers?
intent.putExtra( "return-data", true );
for ( ResolveInfo res : list )
{
final CropOption co = new CropOption();
co.TITLE = getPackageManager().getApplicationLabel( res.activityInfo.applicationInfo );
co.ICON = getPackageManager().getApplicationIcon( res.activityInfo.applicationInfo );
co.CROP_APP = new Intent( intent );
co.CROP_APP.setComponent( new ComponentName( res.activityInfo.packageName, res.activityInfo.name ) );
cropOptions.add( co );
}
// set up the chooser dialog
CropOptionAdapter adapter = new CropOptionAdapter( this, cropOptions );
AlertDialog.Builder builder = new AlertDialog.Builder( this );
builder.setTitle( R.string.choose_crop_title );
builder.setAdapter( adapter, new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dialog, int item )
{
startActivityForResult( cropOptions.get( item ).CROP_APP, ACTIVITY_CROP );
}
} );
builder.setOnCancelListener( new DialogInterface.OnCancelListener() {
@Override
public void onCancel( DialogInterface dialog )
{
// we don't want to keep the capture around if we cancel the crop because we don't want it anymore
if ( _captureUri != null )
{
getContentResolver().delete( _captureUri, null, null );
_captureUri = null;
}
}
} );
AlertDialog alert = builder.create();
alert.show();
}
catch ( Exception e )
{
Log.e( TAG, "processing capture", e );
}
Run Code Online (Sandbox Code Playgroud)
而且你有它...希望有所帮助,我失去了2天试图解决它...
小智 5
我在剪切联系人图片时通过跟踪LogCat找到了一种方法.它使用以下参数调用Intent:
cmp=com.android.gallery/com.android.camera.CropImage
Run Code Online (Sandbox Code Playgroud)
因此,尝试更换com.android.camera用com.android.gallery.这对我有用:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.android.gallery", "com.android.camera.CropImage");
Run Code Online (Sandbox Code Playgroud)
在某些Android版本上,包括最新版本,com.android.gallery不再存在.你需要使用它:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setClassName("com.google.android.gallery3d", "com.android.gallery3d.app.CropImage");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19012 次 |
| 最近记录: |