Android: Can you declare an ImageView intent in androidmanifest



(Rookie android developer)


I am writing an android app that can import a picture from the gallery or camera in the Myactivity.java class, this part works. When I want to save the selected image and send it to the PictureMover.java class using an Intent ( MyActvity extends Activity and PictureMover extends ImageView) The problem is, that the Intent can only be declared in the android manifest under the Activity tab. Since my extends ImageView class is not an activity class I don't know how to declare the intent in the manifest.. ( can a non Activity receive the Intent??). If I can't use the Intent like this, could you recommend me a way to get this image from MyActivity to PictureMover using local storage somehow?


Background story:

The reason I am using the extends ImageView is that I wan't to play around with the picture make it bigger or lager by pinching and when i touch on the screen the picture should move there. The piture has to maintain aspect ratio


MyActivity.java send Intent to PictureMover



protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

if(resultCode==RESULT_OK){
Uri imageuri = imageReturnedIntent.getData();
try {
Bitmap imageFromIntent = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageuri);
Intent sendPicture = new Intent(this,PictureMover.class);
sendPicture.putExtra("URI", imageuri.toString());
startActivity(sendPicture);
// tried but the following, but nullpointers.
/* FileOutputStream fos = openFileOutput("picture", Context.MODE_PRIVATE);
fos.write(imageFromIntent.getRowBytes());
fos.close();*/
setContentView(R.layout.activity_my);
} catch (IOException e) {
e.printStackTrace();
}

}
}


PictureMover receiving intent (note no syntax errors, only semantic I guess.)



public PictureMover(Context context, AttributeSet attrs) {
super(context, attrs);
}
private Runnable runnable=new Runnable() {
@Override
public void run() {
invalidate();
}
};
protected void onDraw(Canvas canvas){
try {
Intent intent=null;
String intentUri = null;
intent=Intent.parseUri(intentUri,0);

String uri = intent.getStringExtra("URI");
Uri imageUri =Uri.parse(uri);
byte [] encodeByte= Base64.decode(uri, Base64.DEFAULT);
Bitmap pictureInput=BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
// tried to receive the stream.

//FileInputStream fis= new FileInputStream("picture");
//Bitmap pictureInput= BitmapFactory.decodeStream(fis);

picture= new BitmapDrawable(getResources(),pictureInput);
picture.setBounds(0,0,100,100);
canvas.drawBitmap(picture.getBitmap(),500,500,null);
handler.postDelayed(runnable,FRAME_RATE);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}


the untouched manifest



<?xml version="1.0" encoding="utf-8"?>



<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- error here PictureMover is not an activity-->
<activity android:name=".PictureMover"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>


the layout



<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/white"
tools:context="${relativePackage}.${activityClass}" >


<com.example.johannes.mad2014_ha3_2.PictureMover
android:id="@+id/anim_view"
android:layout_height="fill_parent"
android:layout_width="fill_parent"/>
</RelativeLayout>


(the error message) 'com.example.johannes.mad2014_ha3_2.PictureMover' has no default constructor less... (Ctrl+F1) Validates resource references inside Android XML files. 'com.example.johannes.mad2014_ha3_2.PictureMover' is not assignable to 'android.app.Activity' less... (Ctrl+F1) Validates resource references inside Android XML files.


No comments:

Post a Comment