Monthly Archives: December 2013

Android Full Screen Video Playing

1.VideoApp.java

package com.javapages4all.videoapp;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;

public class VideoApp extends Activity
{
VideoView mVideoView;
MediaController mc;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.videoapp);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//if you want.

//File video = new File(“your file path”);
mVideoView = (VideoView) findViewById(R.id.myvideoview);
mc = new MediaController(this);
mVideoView.setMediaController(mc);
mc.setAnchorView(mVideoView);
mVideoView.setMediaController(mc);
//mVideoView.setVideoPath(video.getAbsolutePath());
mVideoView.setVideoURI(Uri.parse(“http://www.pocketjourney.com/downloads/pj/video/famous.3gp”));
mVideoView.requestFocus();
mVideoView.start();
}
}

2.videoapp.xml

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent” >
<VideoView android:id=”@+id/myvideoview”
android:layout_width=”fill_parent”
android:layout_alignParentRight=”true”
android:layout_alignParentLeft=”true”
android:layout_alignParentTop=”true”
android:layout_alignParentBottom=”true”
android:layout_height=”fill_parent”>
</VideoView>
</RelativeLayout>

 

3.AndroidManifest.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
package=”com.javapages4all.videoapp”
android:versionCode=”1″
android:versionName=”1.0″ >

<uses-sdk
android:minSdkVersion=”8″
android:targetSdkVersion=”18″ />

<uses-permission android:name=”android.permission.INTERNET” />

<application
android:allowBackup=”true”
android:icon=”@drawable/ic_launcher”
android:label=”@string/app_name”
android:theme=”@style/AppTheme” >
<activity
android:name=”com.javapages4all.videoapp.VideoApp”
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>

</manifest>

 

admin Privilege for Tomcat7 in Windows

Right click on the tomcat7.exe (found at %CATALINA_HOME%\bin). Click on the Properties menu item and then select the Compatibility tab. Check the Run this program as an administrator checkbox under the Privilege Level section. Click the OK button.

admin Privilege for Tomcat7 in Windows

Getting IMEI Number

1.Android Device:

——————–

Dial *#06# to know your IMEI Number.

2.Direct Process:

——————-

Remove your battery and look for IMEI,you will find it.

3.Android Program:

———————-

You’ll need the

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

permission in AndroidManifest.xml file to do this.

final TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

String deviceid = tm.getDeviceId();

File Encryption and Decryption in Java And Android

package raja.JavaPages4all;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;

public class AES
{
private static final String key = “1234567891234567”;
private static final String method = “AES”;
/**
* @param args
*/
public static void main(String[] args)
{
try
{
long stime=System.currentTimeMillis();
File inFile = new File(“D:/sample.wmv”);
File outFile = new File(“D:/sample_encrypted.wmv”);
File outFile_dec = new File(“D:/sample_decrypted.wmv”);
encrypt(new FileInputStream(inFile), new FileOutputStream(outFile));
long etime=System.currentTimeMillis();
System.out.println((etime-stime));
decrypt(new FileInputStream(outFile), new FileOutputStream(outFile_dec));
System.out.println(System.currentTimeMillis()-etime);
} catch (Exception e)
{
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
}

public static SecretKeySpec keyGen(String s) throws NoSuchAlgorithmException
{
KeyGenerator kgen = KeyGenerator.getInstance(method);
kgen.init(128); // 192 and 256 bits may not be available
byte[] raw = s.getBytes();
SecretKeySpec result = new SecretKeySpec(raw, method);
//System.out.println(“result “+new String(result.getEncoded()));
// Instantiate the cipher
return result;
}

public static void encrypt(InputStream is, OutputStream os)
{
encryptOrDecrypt(Cipher.ENCRYPT_MODE, is, os);
}

public static void decrypt(InputStream is, OutputStream os)
{
encryptOrDecrypt(Cipher.DECRYPT_MODE, is, os);
}

public static void encryptOrDecrypt(int mode, InputStream is, OutputStream os)
{
try
{
Cipher cipher = Cipher.getInstance(method); // DES/ECB/PKCS5Padding for SunJCE
if (mode == Cipher.ENCRYPT_MODE)
{
cipher.init(Cipher.ENCRYPT_MODE, keyGen(key));
CipherInputStream cis = new CipherInputStream(is, cipher);
doCopy(cis, os);
} else if (mode == Cipher.DECRYPT_MODE)
{
cipher.init(Cipher.DECRYPT_MODE, keyGen(key));
CipherOutputStream cos = new CipherOutputStream(os, cipher);
doCopy(is, cos);
}
} catch (Exception e)
{
e.printStackTrace();
} catch (Throwable e)
{
e.printStackTrace();
}
}

public static void doCopy(InputStream is, OutputStream os) throws IOException
{
/* byte[] bytes = new byte[1024];
int numBytes;
while ((numBytes = is.read(bytes)) != -1) {
os.write(bytes, 0, numBytes);
}
os.flush();
os.close();
is.close();*/

byte[] buffer = new byte[8192]; // Or larger (but use powers of 2)
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1)
{
os.write(buffer, 0, bytesRead);
}
os.flush();
os.close();
is.close();
}

}

%d bloggers like this: