Playing a video file is simple in android. This post will help you.
Put your video in res/raw folder. If no raw folder present then create a new folder inside res.
package com.coderzheaven.pack;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class Example extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showVideo();
}
private void showVideo()
{
VideoView vd = (VideoView)findViewById(R.id.videoview);
Uri uri = Uri.parse("android.resource://package/"+R.raw.movie);
MediaController mc = new MediaController(this);
vd.setMediaController(mc);
vd.setVideoURI(uri);
vd.start();
}
}
The main. xml file.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<VideoView
android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
>
</VideoView>
</RelativeLayout>
Please leave your comments if this post was useful.
The following code helps you to do a drag and drop in ANDROID.
package com.pack;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.ImageView;
public class Touch extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyView tx = new MyView(this);
MyView2 tx2 = new MyView2(this);
tx.setText("Drag Me");
int imgID = getResources().getIdentifier("icon", "drawable", "com.pack");
tx2.setImageResource(imgID);
AbsoluteLayout l = new AbsoluteLayout(this);
AbsoluteLayout.LayoutParams p = new AbsoluteLayout.LayoutParams(
AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,0,0);
l.addView(tx,p);
l.addView(tx2,p);
setContentView(l);
}
// events when touching the screen
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
int X = (int)event.getX();
int Y = (int)event.getY();
System.out.println("SCR X="+X+" SCR y="+Y);
switch (eventaction ) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
/******************* Class 1 ************************************/
class MyView extends Button
{
public MyView(Context c){
super(c);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int mCurX = (int)event.getRawX();
int mCurY = (int)event.getRawY();;
System.out.println("scrollx "+this.getScrollX());
int action = event.getAction();
if ( action == MotionEvent.ACTION_MOVE ) {
System.out.println("X="+mCurX+" y="+mCurY);
this.setText("x: " + mCurX + ",y: " + mCurY );
AbsoluteLayout.LayoutParams p = new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,mCurX-50,mCurY-50);
this.setLayoutParams (p);
}
return true;
}
public void draw(Canvas canvas) {
super.draw(canvas);
}
}
/******************* Class 2 ************************************/
class MyView2 extends ImageView
{
public MyView2(Context c){
super(c);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int mCurX = (int)event.getRawX();
int mCurY = (int)event.getRawY();;
System.out.println("scrollx "+this.getScrollX());
int action = event.getAction();
if ( action == MotionEvent.ACTION_MOVE ) {
System.out.println("X="+mCurX+" y="+mCurY);
int imgID = getResources().getIdentifier("icon", "drawable", "com.pack");
this.setImageResource(imgID);
AbsoluteLayout.LayoutParams p = new AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,this.getScrollX()+ mCurX,this.getScrollY()+mCurY);
this.setLayoutParams (p);
}
return true;
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
}
}
}
By using the below code snippet you can uninstall an installed application on your ANDROID phone.
Create an intent object with an action and data as the package name and start with the ACTION_DELETE.
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.pack.Applicationname"));
startActivity(intent);
Call this function to restart your application
var app:WindowedApplication = WindowedApplication(Application.application);
var mgr:ProductManager = new ProductManager("airappinstaller");
mgr.launch("-launch " + app.nativeApplication.applicationID + " " + app.nativeApplication.publisherID);
app.close();
Note : PLease add this to your app.XML file inorder for the above code to work.
This sample code helps you to load html from a string and from a file into webview in ANDROID.
String str = Your HTML String;
/*
use src='file:///android_asset/images/photo_3.jpg' for loading images from
the assets /images folder
*/
/* To load from a string use loadDataWithBaseURL */
webview.loadDataWithBaseURL("",str , "text/html", "utf-8", "");
/* To load from a file use loadUrl(remote or local) */
webview.loadUrl("file:///android_asset/test.html");