gpt4 book ai didi

android - 无法在 android 中找到 com.android.camera.CropImage Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:33 25 4
gpt4 key购买 nike

我正在尝试从以下链接运行 PhotoStream 示例

http://android-developers.blogspot.com/2008/09/android-photostream.html

但是当我尝试设置图像的墙纸时(引用类 ViewPhotoActivity.java),出现以下错误

android.content.ActivityNotFoundException:

Unable to find explicit activity class {com.android.camera/com.android.camera.CropImage}; have you declared this activity in your 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);

因为我试图找到这个问题的解决方案但没有得到任何解决方案。

最佳答案

实际上,有相当多的应用程序在 Android 2.x 中提供 CROP 操作:标准图库或 Flikie Wallpapers(仅举几例)。为什么解析 Intent 成功失败,是谷歌更改了提供 API 的组件。在 Android 1.x 中可能是 com.android.gallery,但自从(我认为)API9/Android 2.3.x 以来,默认图库由 Cooliris 提供,因此它类似于 com.cooliris.gallery 等。

在任何手机上解析 Intent 的正确方法是(我使用的代码):

// 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;
}
}

项目的布局应该是带有 IconView 和 TextView 的水平线性布局。为了简洁起见,我将跳过它,现在你很可能知道如何去做:-)

现在是我们找到 Intent 并将其呈现以供选择的部分(这只是函数的相关部分,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 );
}

好了...希望对您有所帮助,我花了 2 天的时间才弄明白...

关于android - 无法在 android 中找到 com.android.camera.CropImage Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3904685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com