Tuesday, 11 September 2012

Android, Create File

How to create Folder on External Memory in Android.

public boolean isExternalStorageWritable() {
  if (Environment.MEDIA_MOUNTED.equals(Environment
                        .getExternalStorageState()))
     return true;
   else
       return false;
   }

File folder;

if (isExternalStorageWritable()) {
      dbFolder = new File(
                    Environment.getExternalStorageDirectory()
                               + File.separator + "Mohammad");                
   }
  boolean success = false;
  if (!dbFolder.exists()) {
      success = dbFolder.mkdir();//one directory
// success = dbFolder.mkdir(); to create more than one directory 
//                        like "Mohammad/kaied/abuhmead"
  }
  if (!success) {
            DB_DIRE=null;
         }
  

Mohammad Abu Hmead

Tuesday, 4 September 2012

Android; Read file from Assets into Byte Array

Sometimes you want to place an encrypted file in the assets folder, and you want to read it in correct and unencrypted, so, you want to read it into byte array and edit the byte array to the correct format, here is the way


InputStream is=getAssets().open("fileName.extension");
byte[] fileBytes=new byte[is.available()];
is.read( fileBytes);
is.close();

Now you edit the byte array as you want, and you can create original file with the current bytes if it was encrypted



Mohammad Abu Hmead

Wednesday, 29 August 2012

Backup MSSQL Database from Command Prompt

Start the command prompt and type the following:

C:\Users\Administrator>sqlcmd -E -Q "backup database databaseName to disk='C:\backups\ databaseName.bak' with format" > "C:\backups\backUpLog.log"

The text which hi-lighted by green color it is the cmd default 

Hint: with format is used to delete the previous backup and create new one, if you want the current backup to be pushed to the previous one just don't type-write- it.



You can backup more than one database in the same command like the following
"backup database databaseName to disk='C:\backups\ databaseName.bak' with format backup database databaseName to disk='C:\backups\ databaseName.bak' with format" and so on

Backup using Batch file:
You can Create sql query file like"backupDBs.sql" and type in it
backup database databaseName to disk='C:\backups\ databaseName.bak' with format
and call it to be executed from batch file which contains the following command
sqlcmd -s . -i "C:\backupDBs .sql" > "C:\backupDBLog.log"
and you can  Schedule it as you want via Scheduled Tasks

or you can place sqlcmd -E -Q "backup database databaseName to disk='C:\backups\ databaseName.bak' with format" > "C:\backups\backUpLog.log" in the batch file

1- Navigate to Control Panel, Scheduled Tasks, Add New Task, and select Command Prompt
2- Change the task path to backupdb.bat, start path to C:\ and set how often you want to backup


Mohammad Abu Hmead

Thursday, 9 August 2012

الأحرف العربية تظهر بعلامات سؤال




أنا جهازي عليه Windows XP SP3 في ملفات اسماءها بالعربي 


بعرض اسماءها á¬dƒOñ ƒT¬Of¬ ƒT¬nƒaní áƒTp¬án

وملفات أخرى بيكون بداخلها نصوص عربي بيعرضها ???????


شو الحل؟

go to:

control panel> lang settings> advanced tab...

select Arabic as "language for non-unicode programs"

and mark as much as you can Arabic-related codes 

from the list; 

Mohammad Abu Hmead

Sunday, 29 July 2012

How To download an image and save to the memory card


/First create a new URL object 
URL url = new URL("http://www.google.co.uk/logos/holiday09_2.gif")
//Next create a file, the example below will save to the SDCARD using JPEG
// format
File file = new File("/sdcard/example.jpg");
//Next create a Bitmap object and download the image to bitmap
Bitmap bitmap = BitmapFactory.decodeStream(url.openStream());
//Finally compress the bitmap, saving to the file previously created
bitmap.compress(CompressFormat.JPEG, 100, new FileOutputStream(file));

Don't forget to add the Internet permission to your manifest:
 android:name="android.permission.INTERNET" />

Mohammad Abu Hmead

Saturday, 23 June 2012

I updated the java and eclipse does not work



I updated the JRE today 23.06.2012, and after that the eclipse does not work, when I double click on eclipse it makes like the camera flash.

What is the solution?

Here is it

I just added this line to the eclipse.ini file
 -vm
C:\Program Files\Java\jdk1.7.0_03\bin\javaw.exe
And it is now running successfully.
Mohammad Abu Hmead

Sunday, 20 May 2012

Install apk on android emulator

To install android application (.apk) on an emulator follow these steps:

1- run the target emulator
2- copy the .apk file into platform-tools folder
3- cd into platform-tools folder
ex: E:\>cd \Android Full Development Platform (SDK+Eclipse)\android-sdk-windows\platform-tools
4- adb install theApkFileName.apk

if you launched more than one emulator, use the following code

adb -s emulator-5556 install  theApkFileName.apk


Hint: make sure adb.exe in the platform-tools folder


Mohammad Abu Hmead