我使用BridgeKit启动一个Intent,然后启动Android图库选择器,然后将所选图像作为字节返回。
Intent正确启动,我甚至可以选择图像并获得PNG表示,但是当我尝试使用回调将字节返回到Obj-C land时,我收到以下错误:
W/dalvikvm( 3417): No implementation found for native Lmystuff/android/AndroidImageSelector;.imagePicked:([B)V
I/System.out( 3417): java.lang.UnsatisfiedLinkError: Native method not found: mystuff.android.AndroidImageSelector.imagePicked:([B)V
意图以:
开头AndroidIntent* intent = [ [AndroidIntent alloc] initWithContext: [ AndroidActivity currentActivity ] class: [ AndroidImageSelector javaClass ] ];
[intent start];
AndroidImageSelector扩展了JavaObject,包括以下方法:
+ (NSString*) className
{
return @"mystuff.android.AndroidImageSelectorActivity";
}
+ (void) initializeJava
{
[ super initializeJava ];
[AndroidImageSelector registerCallback: @"imagePicked"
selector: @selector( imagePicked:)
returnValue: nil
arguments: [NSData className], nil ];
}
- (void) imagePicked: (NSData*) data
{
NSLog( @"IMAGE PICKED: %d", [ data length ] );
}
在Java端,AndroidImageSelectorActivity扩展了Activity并包含:
private native void imagePicked( byte[] response );
protected void onActivityResult( int requestCode, int resultCode, Intent imageReturnedIntent )
{
super.onActivityResult( requestCode, resultCode, imageReturnedIntent );
try
{
switch ( requestCode )
{
case SELECT_PHOTO:
if ( resultCode == RESULT_OK )
{
Uri selectedImage = imageReturnedIntent.getData();
Bitmap bitmap = decodeURI( selectedImage );
ByteArrayOutputStream out0 = new ByteArrayOutputStream();
bitmap.compress( Bitmap.CompressFormat.PNG, 100, out0 );
byte[] pngBytes = out0.toByteArray();
imagePicked( pngBytes );
}
}
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
Intent photoPickerIntent = new Intent( Intent.ACTION_PICK );
photoPickerIntent.setType( "image/*" );
startActivityForResult( photoPickerIntent, SELECT_PHOTO );
}
答案 0 :(得分:1)
你需要在目标c方面实现imagePicked:基本上,你告诉java你将提供java方法的本机实现,但没有一个。
答案 1 :(得分:1)
此错误将在Apportable SDK的下一次更新中修复。对于那个很抱歉。