Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 22.02 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Camera service crashes in Android
  2. import java.io.FileOutputStream;
  3. import java.io.IOException;
  4. import java.util.List;
  5.  
  6. import android.app.Activity;
  7. import android.content.Intent;
  8. import android.graphics.PixelFormat;
  9. import android.hardware.Camera;
  10. import android.hardware.Camera.Size;
  11.  
  12. import android.net.Uri;
  13. import android.os.Bundle;
  14. import android.os.Environment;
  15.  
  16. import android.util.Log;
  17. import android.view.KeyEvent;
  18. import android.view.SurfaceHolder;
  19. import android.view.SurfaceView;
  20. import android.view.View;
  21. import android.view.View.OnClickListener;
  22. import android.view.Window;
  23. import android.widget.Button;
  24. import android.widget.Toast;
  25.  
  26. public class TakePictureActivity extends Activity implements
  27.         SurfaceHolder.Callback {
  28.     private Camera mCamera;
  29.     private Button takePictureButton;
  30.     private SurfaceView mSurfaceView;
  31.     private SurfaceHolder mSurfaceHolder;
  32.     private boolean mPreviewRunning;
  33.     private String currentPictureName;
  34.     private String sdcardPath = "/sdcard/DCIM";
  35.  
  36.     Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
  37.         @Override
  38.         public void onPictureTaken(byte[] data, Camera c) {
  39.             currentPictureName = Long.toString(System.currentTimeMillis())
  40.                     + ".jpg";
  41.  
  42.             FileOutputStream outStream = null;
  43.             try {
  44.                 outStream = new FileOutputStream(sdcardPath
  45.                         + currentPictureName);
  46.                 outStream.write(data);
  47.                 outStream.close();
  48.  
  49.                 sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
  50.                         Uri.parse("file://"
  51.                                 + Environment.getExternalStorageDirectory())));
  52.             } catch (Exception e) {
  53.                 e.printStackTrace();
  54.             } finally {
  55.                 mCamera.startPreview();
  56.             }
  57.         }
  58.     };
  59.  
  60.     @Override
  61.     public void onCreate(Bundle savedInstanceState) {
  62.         super.onCreate(savedInstanceState);
  63.         requestWindowFeature(Window.FEATURE_NO_TITLE);
  64.         getWindow().setFormat(PixelFormat.TRANSLUCENT);
  65.         setContentView(R.layout.takepicture);
  66.  
  67.         mSurfaceView = (SurfaceView) findViewById(R.id.preview);
  68.         mSurfaceHolder = mSurfaceView.getHolder();
  69.         mSurfaceHolder.addCallback(this);
  70.         mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  71.  
  72.         takePictureButton = (Button) findViewById(R.id.buttonTakePhoto);
  73.         takePictureButton.setOnClickListener(new OnClickListener() {
  74.             public void onClick(View v) {
  75.                 mCamera.takePicture(null, null, mPictureCallback);
  76.             }
  77.         });
  78.     }
  79.  
  80.     public void surfaceCreated(SurfaceHolder holder) {
  81.         mCamera = Camera.open();
  82.     }
  83.  
  84.     private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
  85.         final double ASPECT_TOLERANCE = 0.1;
  86.         double targetRatio = (double) w / h;
  87.         if (sizes == null)
  88.             return null;
  89.  
  90.         Size optimalSize = null;
  91.         double minDiff = Double.MAX_VALUE;
  92.  
  93.         int targetHeight = h;
  94.  
  95.         // Try to find an size match aspect ratio and size
  96.         for (Size size : sizes) {
  97.             double ratio = (double) size.width / size.height;
  98.             if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
  99.                 continue;
  100.             if (Math.abs(size.height - targetHeight) < minDiff) {
  101.                 optimalSize = size;
  102.                 minDiff = Math.abs(size.height - targetHeight);
  103.             }
  104.         }
  105.  
  106.         // Cannot find the one match the aspect ratio, ignore the requirement
  107.         if (optimalSize == null) {
  108.             minDiff = Double.MAX_VALUE;
  109.             for (Size size : sizes) {
  110.                 if (Math.abs(size.height - targetHeight) < minDiff) {
  111.                     optimalSize = size;
  112.                     minDiff = Math.abs(size.height - targetHeight);
  113.                 }
  114.             }
  115.         }
  116.         return optimalSize;
  117.     }
  118.  
  119.     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
  120.         if (mPreviewRunning) {
  121.             mCamera.stopPreview();
  122.         }
  123.         Camera.Parameters p = mCamera.getParameters();
  124.         List<Camera.Size> previewSizes = p.getSupportedPreviewSizes();
  125.         Size s = getOptimalPreviewSize(previewSizes, w, h);
  126.  
  127.         p.setPreviewSize(s.width, s.height);
  128.         // p.setPreviewSize(s.height, s.width);
  129.         mCamera.setParameters(p);
  130.         try {
  131.             mCamera.setPreviewDisplay(holder);
  132.         } catch (IOException e) {
  133.             e.printStackTrace();
  134.         }
  135.         mCamera.startPreview();
  136.         mPreviewRunning = true;
  137.     }
  138.  
  139.     public void surfaceDestroyed(SurfaceHolder holder) {
  140.         if (mCamera != null) {
  141.             mCamera.stopPreview();
  142.             mCamera.setPreviewCallback(null);
  143.             mCamera.release();
  144.             mCamera = null;
  145.         }
  146.     }
  147.  
  148.     public boolean onKeyDown(int keyCode, KeyEvent event) {
  149.         if (keyCode == KeyEvent.KEYCODE_BACK) {
  150.             return super.onKeyDown(keyCode, event);
  151.         }
  152.  
  153.         if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
  154.             mCamera.takePicture(null, null, mPictureCallback);
  155.             return true;
  156.         }
  157.         return false;
  158.     }
  159.  
  160.     public void snapClicked(View view) {
  161.         Log.e("@@@@@@@@@", "snapclicked called");
  162.         mCamera.takePicture(null, null, mPictureCallback);
  163.         Toast.makeText(this, "Picture saved on sd card", Toast.LENGTH_SHORT)
  164.                 .show();
  165.     }
  166. }
  167.        
  168. <?xml version="1.0" encoding="utf-8"?>
  169. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  170.     package="com.apps.objectdetection"
  171.     android:versionCode="1"
  172.     android:versionName="1.0" >
  173.  
  174.     <uses-sdk android:minSdkVersion="10" />
  175.  
  176.     <application
  177.         android:icon="@drawable/ic_launcher"
  178.         android:label="@string/app_name" >
  179.         <activity
  180.             android:label="@string/app_name"
  181.             android:name=".ObjectDetection" >
  182.             <intent-filter >
  183.                 <action android:name="android.intent.action.MAIN" />
  184.  
  185.                 <category android:name="android.intent.category.LAUNCHER" />
  186.             </intent-filter>
  187.         </activity>
  188.         <activity android:name=".TakePictureActivity" />
  189.         <activity android:name=".AnalyzeActivity" />
  190.     </application>
  191.  
  192.     <uses-permission android:name="android.permission.CAMERA" />
  193.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  194.  
  195.     <uses-feature android:name="android.hardware.camera" />
  196.     <uses-feature android:name="android.hardware.camera.autofocus" />
  197.  
  198. </manifest>
  199.        
  200. I/PackageManager(   69): Removing non-system package:com.apps.objectdetection
  201. I/ActivityManager(   69): Force stopping package com.apps.objectdetection uid=10036
  202. D/PackageManager(   69): Scanning package com.apps.objectdetection
  203. I/PackageManager(   69): Package com.apps.objectdetection codePath changed from /data/app/com.apps.objectdetection-1.apk to /data/app/com.apps.objectdetection-2.apk; Retaining data and using new
  204. I/PackageManager(   69): Unpacking native libraries for /data/app/com.apps.objectdetection-2.apk
  205. D/dalvikvm(   69): GC_CONCURRENT freed 1266K, 48% free 4269K/8199K, external 4373K/5573K, paused 9ms+7ms
  206. D/installd(   35): DexInv: --- BEGIN '/data/app/com.apps.objectdetection-2.apk' ---
  207. D/dalvikvm(  333): DexOpt: load 64ms, verify+opt 376ms
  208. D/installd(   35): DexInv: --- END '/data/app/com.apps.objectdetection-2.apk' (success) ---
  209. W/PackageManager(   69): Code path for pkg : com.apps.objectdetection changing from /data/app/com.apps.objectdetection-1.apk to /data/app/com.apps.objectdetection-2.apk
  210. W/PackageManager(   69): Resource path for pkg : com.apps.objectdetection changing from /data/app/com.apps.objectdetection-1.apk to /data/app/com.apps.objectdetection-2.apk
  211. D/PackageManager(   69):   Activities: com.apps.objectdetection.ObjectDetection com.apps.objectdetection.TakePictureActivity com.apps.objectdetection.AnalyzeActivity
  212. I/ActivityManager(   69): Force stopping package com.apps.objectdetection uid=10036
  213. I/installd(   35): move /data/dalvik-cache/data@app@com.apps.objectdetection-2.apk@classes.dex -> /data/dalvik-cache/data@app@com.apps.objectdetection-2.apk@classes.dex
  214. D/PackageManager(   69): New package installed in /data/app/com.apps.objectdetection-2.apk
  215. I/ActivityManager(   69): Force stopping package com.apps.objectdetection uid=10036
  216. D/dalvikvm(  139): GC_EXPLICIT freed 75K, 52% free 2908K/5959K, external 4984K/5293K, paused 65ms
  217. D/dalvikvm(  194): GC_EXPLICIT freed 292K, 52% free 2769K/5703K, external 1625K/2137K, paused 158ms
  218. I/ActivityManager(   69): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=334 uid=10009 gids={}
  219. W/RecognitionManagerService(   69): no available voice recognition services found
  220. I/ActivityThread(  334): Pub com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider
  221. D/dalvikvm(   69): GC_EXPLICIT freed 445K, 49% free 4242K/8199K, external 4373K/5573K, paused 80ms
  222. I/installd(   35): unlink /data/dalvik-cache/data@app@com.apps.objectdetection-1.apk@classes.dex
  223. D/AndroidRuntime(  240): Shutting down VM
  224. D/dalvikvm(  240): GC_CONCURRENT freed 100K, 72% free 293K/1024K, external 0K/0K, paused 3ms+1ms
  225. D/jdwp    (  240): adbd disconnected
  226. I/AndroidRuntime(  240): NOTE: attach of thread 'Binder Thread #3' failed
  227. D/AndroidRuntime(  347):
  228. D/AndroidRuntime(  347): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
  229. D/AndroidRuntime(  347): CheckJNI is ON
  230. D/AndroidRuntime(  347): Calling main entry com.android.commands.am.Am
  231. I/ActivityManager(   69): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.apps.objectdetection/.ObjectDetection } from pid 347
  232. I/ActivityManager(   69): Start proc com.apps.objectdetection for activity com.apps.objectdetection/.ObjectDetection: pid=355 uid=10036 gids={1006, 1015}
  233. D/AndroidRuntime(  347): Shutting down VM
  234. D/dalvikvm(  347): GC_CONCURRENT freed 101K, 69% free 318K/1024K, external 0K/0K, paused 2ms+1ms
  235. D/jdwp    (  347): adbd disconnected
  236. I/AndroidRuntime(  347): NOTE: attach of thread 'Binder Thread #3' failed
  237. E/TAG     (  355): OD onCraete called!
  238. D/CameraHardwareStub(   34): initHeapLocked: preview size=320x240
  239. I/StagefrightPlayer(   34): setDataSource('/system/media/audio/ui/camera_click.ogg')
  240. I/StagefrightPlayer(   34): setDataSource('/system/media/audio/ui/VideoRecord.ogg')
  241. D/CameraHardwareStub(   34): initHeapLocked: preview size=320x240
  242. I/ActivityManager(   69): Displayed com.apps.objectdetection/.ObjectDetection: +2s500ms (total +46s538ms)
  243. I/ActivityManager(   69): Displayed com.android.launcher/com.android.launcher2.Launcher: +46s542ms
  244. I/InputReader(   69): Device reconfigured: id=0x0, name=qwerty2, display size is now 480x800
  245. I/InputManager-Callbacks(   69): No virtual keys found for device qwerty2.
  246. I/ARMAssembler(   69): generated scanline__00000177:03515104_00001002_00000000 [ 87 ipp] (110 ins) at [0x444ea520:0x444ea6d8] in 2041001 ns
  247. I/ARMAssembler(   69): generated scanline__00000077:03515104_00001004_00000000 [ 65 ipp] (85 ins) at [0x444ea6e0:0x444ea834] in 701000 ns
  248. I/ARMAssembler(   69): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x444ea838:0x444eaa00] in 642000 ns
  249. E/SurfaceFlinger(   69): texture=11, using format 17, which is not supported by the GL
  250. D/AudioSink(   34): bufferCount (4) is too small and increased to 12
  251. E/SurfaceFlinger(   69): texture=7, using format 17, which is not supported by the GL
  252. D/MediaScannerService(  226): start scanning volume external
  253. V/MediaScanner(  226): pruneDeadThumbnailFiles... android.database.sqlite.SQLiteCursor@40528098
  254. V/MediaScanner(  226): /pruneDeadThumbnailFiles... android.database.sqlite.SQLiteCursor@40528098
  255. D/MediaScanner(  226):  prescan time: 81ms
  256. D/MediaScanner(  226):     scan time: 53ms
  257. D/MediaScanner(  226): postscan time: 26ms
  258. D/MediaScanner(  226):    total time: 160ms
  259. D/MediaScannerService(  226): done scanning volume external
  260. E/SurfaceFlinger(   69): texture=7, using format 17, which is not supported by the GL
  261. D/MediaScannerService(  226): start scanning volume external
  262. D/MediaScanner(  226):  prescan time: 88ms
  263. D/MediaScanner(  226):     scan time: 55ms
  264. D/MediaScanner(  226): postscan time: 0ms
  265. D/MediaScanner(  226):    total time: 143ms
  266. D/MediaScannerService(  226): done scanning volume external
  267. I/InputDispatcher(   69): Application is not responding: Window{4074e398 com.apps.objectdetection/com.apps.objectdetection.ObjectDetection paused=false}.  5006.2ms since event, 5005.8ms since wait started
  268. I/WindowManager(   69): Input event dispatching timed out sending to com.apps.objectdetection/com.apps.objectdetection.ObjectDetection
  269. I/Process (   69): Sending signal. PID: 355 SIG: 3
  270. I/dalvikvm(  355): threadid=4: reacting to signal 3
  271. I/dalvikvm(  355): Wrote stack traces to '/data/anr/traces.txt'
  272. I/Process (   69): Sending signal. PID: 69 SIG: 3
  273. I/dalvikvm(   69): threadid=4: reacting to signal 3
  274. I/dalvikvm(   69): Wrote stack traces to '/data/anr/traces.txt'
  275. I/Process (   69): Sending signal. PID: 131 SIG: 3
  276. I/dalvikvm(  131): threadid=4: reacting to signal 3
  277. I/dalvikvm(  131): Wrote stack traces to '/data/anr/traces.txt'
  278. I/Process (   69): Sending signal. PID: 135 SIG: 3
  279. I/dalvikvm(  135): threadid=4: reacting to signal 3
  280. I/dalvikvm(  135): Wrote stack traces to '/data/anr/traces.txt'
  281. D/dalvikvm(   69): GC_EXPLICIT freed 479K, 48% free 4310K/8199K, external 4373K/5573K, paused 130ms
  282. I/Process (   69): Sending signal. PID: 226 SIG: 3
  283. I/dalvikvm(  226): threadid=4: reacting to signal 3
  284. I/dalvikvm(  226): Wrote stack traces to '/data/anr/traces.txt'
  285. E/ActivityManager(   69): ANR in com.apps.objectdetection (com.apps.objectdetection/.ObjectDetection)
  286. E/ActivityManager(   69): Reason: keyDispatchingTimedOut
  287. E/ActivityManager(   69): Load: 2.06 / 1.16 / 0.44
  288. E/ActivityManager(   69): CPU usage from 28574ms to 0ms ago:
  289. E/ActivityManager(   69):   0.2% 41/adbd: 0% user + 0.2% kernel / faults: 64 minor
  290. E/ActivityManager(   69):   0.1% 69/system_server: 0.1% user + 0% kernel / faults: 2 minor
  291. E/ActivityManager(   69):   0% 131/com.android.phone: 0% user + 0% kernel / faults: 7 minor
  292. E/ActivityManager(   69): 1.2% TOTAL: 0.4% user + 0.8% kernel + 0% softirq
  293. E/ActivityManager(   69): CPU usage from 985ms to 1562ms later:
  294. E/ActivityManager(   69):   14% 69/system_server: 7.1% user + 7.1% kernel / faults: 5 minor
  295. E/ActivityManager(   69):     8.9% 103/InputDispatcher: 5.3% user + 3.5% kernel
  296. E/ActivityManager(   69):     5.3% 70/HeapWorker: 1.7% user + 3.5% kernel
  297. E/ActivityManager(   69):   1% 226/android.process.media: 1% user + 0% kernel
  298. E/ActivityManager(   69):     1% 233/Binder Thread #: 1% user + 0% kernel
  299. E/ActivityManager(   69): 17% TOTAL: 7% user + 10% kernel
  300. I/InputDispatcher(   69): Dropping event because the pointer is not down.
  301. D/SntpClient(   69): request time failed: java.net.SocketException: Address family not supported by protocol
  302. I/dalvikvm(   69): Jit: resizing JitTable from 1024 to 2048
  303. D/SntpClient(   69): request time failed: java.net.SocketException: Address family not supported by protocol
  304. D/SntpClient(   69): request time failed: java.net.SocketException: Address family not supported by protocol
  305. D/SntpClient(   69): request time failed: java.net.SocketException: Address family not supported by protocol
  306. D/SntpClient(   69): request time failed: java.net.SocketException: Address family not supported by protocol
  307. D/SntpClient(   69): request time failed: java.net.SocketException: Address family not supported by protocol
  308.        
  309. ----- pid 355 at 2012-02-05 23:53:50 -----
  310. Cmd line: com.apps.objectdetection
  311.  
  312. DALVIK THREADS:
  313. (mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
  314. "main" prio=5 tid=1 NATIVE
  315.   | group="main" sCount=1 dsCount=0 obj=0x4001f1a8 self=0xce48
  316.   | sysTid=355 nice=0 sched=0/0 cgrp=default handle=-1345006528
  317.   | schedstat=( 726128083 1938849180 195 )
  318.   at android.hardware.Camera.native_takePicture(Native Method)
  319.   at android.hardware.Camera.takePicture(Camera.java:746)
  320.   at android.hardware.Camera.takePicture(Camera.java:710)
  321.   at com.apps.objectdetection.TakePictureActivity$2.onClick(TakePictureActivity.java:76)
  322.   at android.view.View.performClick(View.java:2485)
  323.   at android.view.View$PerformClick.run(View.java:9080)
  324.   at android.os.Handler.handleCallback(Handler.java:587)
  325.   at android.os.Handler.dispatchMessage(Handler.java:92)
  326.   at android.os.Looper.loop(Looper.java:123)
  327.   at android.app.ActivityThread.main(ActivityThread.java:3683)
  328.   at java.lang.reflect.Method.invokeNative(Native Method)
  329.   at java.lang.reflect.Method.invoke(Method.java:507)
  330.   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  331.   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  332.   at dalvik.system.NativeStart.main(Native Method)
  333.  
  334. "Binder Thread #2" prio=5 tid=8 NATIVE
  335.   | group="main" sCount=1 dsCount=0 obj=0x40512758 self=0x1f8c40
  336.   | sysTid=367 nice=0 sched=0/0 cgrp=default handle=2557464
  337.   | schedstat=( 12951001 32247003 12 )
  338.   at dalvik.system.NativeStart.run(Native Method)
  339.  
  340. "Binder Thread #1" prio=5 tid=7 NATIVE
  341.   | group="main" sCount=1 dsCount=0 obj=0x405111b0 self=0x117770
  342.   | sysTid=366 nice=0 sched=0/0 cgrp=default handle=1144624
  343.   | schedstat=( 18285003 36422003 16 )
  344.   at dalvik.system.NativeStart.run(Native Method)
  345.  
  346. "Compiler" daemon prio=5 tid=6 VMWAIT
  347.   | group="system" sCount=1 dsCount=0 obj=0x4050eca8 self=0x116c00
  348.   | sysTid=365 nice=0 sched=0/0 cgrp=default handle=1143144
  349.   | schedstat=( 2489001 48433004 6 )
  350.   at dalvik.system.NativeStart.run(Native Method)
  351.  
  352. "JDWP" daemon prio=5 tid=5 VMWAIT
  353.   | group="system" sCount=1 dsCount=0 obj=0x4050ebf8 self=0x116ac8
  354.   | sysTid=364 nice=0 sched=0/0 cgrp=default handle=580152
  355.   | schedstat=( 22429003 84657008 23 )
  356.   at dalvik.system.NativeStart.run(Native Method)
  357.  
  358. "Signal Catcher" daemon prio=5 tid=4 RUNNABLE
  359.   | group="system" sCount=0 dsCount=0 obj=0x4050eb38 self=0x116fa8
  360.   | sysTid=363 nice=0 sched=0/0 cgrp=default handle=576032
  361.   | schedstat=( 11413002 30484003 8 )
  362.   at dalvik.system.NativeStart.run(Native Method)
  363.  
  364. "GC" daemon prio=5 tid=3 VMWAIT
  365.   | group="system" sCount=1 dsCount=0 obj=0x4050ea90 self=0x8d848
  366.   | sysTid=358 nice=0 sched=0/0 cgrp=default handle=576384
  367.   | schedstat=( 723000 9093001 2 )
  368.   at dalvik.system.NativeStart.run(Native Method)
  369.  
  370. "HeapWorker" daemon prio=5 tid=2 VMWAIT
  371.   | group="system" sCount=1 dsCount=0 obj=0x4050e9d8 self=0x1165f0
  372.   | sysTid=357 nice=0 sched=0/0 cgrp=default handle=969568
  373.   | schedstat=( 77777007 532447054 23 )
  374.   at dalvik.system.NativeStart.run(Native Method)
  375.  
  376. ----- end 355 -----
  377.        
  378. public class UploadImage extends Activity {
  379.  
  380. Bitmap _bitmap;
  381. File imgFile;
  382. Uri selectedImageUri;
  383. private String filePath;
  384.  
  385.  
  386. /** Called when the activity is first created. */
  387.  
  388. public void onCreate(Bundle savedInstanceState) {
  389.     super.onCreate(savedInstanceState);
  390.     setContentView(R.layout.uploadimage);
  391.  
  392.     imgFile = new File(path);
  393.     // String name=imgFile.
  394.     if (imgFile.exists()) {
  395.  
  396.         selectedImageUri =Upload.selectedUri;
  397.         Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImageUri);
  398.      filePath = null;
  399.  
  400.         try {
  401.             // OI FILE Manager
  402.             String filemanagerstring = selectedImageUri.getPath();
  403.             Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+filemanagerstring);
  404.             // MEDIA GALLERY
  405.             String selectedImagePath = getPath(selectedImageUri);
  406.             Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImagePath);
  407.  
  408.             if (selectedImagePath != null) {
  409.                 filePath = selectedImagePath;
  410.                 Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+selectedImagePath);
  411.             } else if (filemanagerstring != null) {
  412.                 filePath = filemanagerstring;
  413.                 Log.d("uriiiiiiiiiiiii", "uriiiiiiiiiiiiiiiii"+filePath);
  414.             } else {
  415.                 Toast.makeText(getApplicationContext(),"Unknown path",  Toast.LENGTH_LONG).show();
  416.                 Log.e("Bitmap", "Unknown path");
  417.             }
  418.  
  419.             if (filePath != null) {
  420.                 decodeFile(filePath);
  421.             } else {
  422.                 _bitmap = null;
  423.             }
  424.         } catch (Exception e) {
  425.             Toast.makeText(getApplicationContext(), "Internal error",
  426.                     Toast.LENGTH_LONG).show();
  427.             Log.e(e.getClass().getName(), e.getMessage(), e);
  428.         }
  429.  
  430.     }
  431.  
  432.  
  433. public void decodeFile(String filePath) {
  434.     // Decode image size
  435.     BitmapFactory.Options o = new BitmapFactory.Options();
  436.     o.inJustDecodeBounds = true;
  437.     BitmapFactory.decodeFile(filePath, o);
  438.  
  439.     // The new size we want to scale to
  440.     final int REQUIRED_SIZE = 1024;
  441.  
  442.     // Find the correct scale value. It should be the power of 2.
  443.     int width_tmp = o.outWidth, height_tmp = o.outHeight;
  444.     int scale = 1;
  445.     while (true) {
  446.         if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
  447.             break;
  448.         width_tmp /= 2;
  449.         height_tmp /= 2;
  450.         scale *= 2;
  451.     }
  452.  
  453.     // Decode with inSampleSize
  454.     BitmapFactory.Options o2 = new BitmapFactory.Options();
  455.     o2.inSampleSize = scale;
  456.     _bitmap = BitmapFactory.decodeFile(filePath, o2);
  457.  
  458.  
  459.  
  460.     int width = _bitmap.getWidth();
  461.     int height = _bitmap.getHeight();
  462.  
  463.     //new width / heigth
  464.     int newWidth = 300;
  465.     int newHeight = 460;
  466.  
  467.     // calculate the scale
  468.     float scaleWidth = (float) newWidth / width;
  469.     float scaleHeight = (float) newHeight / height;
  470.  
  471.     // create a matrix for the manipulation
  472.     Matrix matrix = new Matrix();
  473.    // matrix.preRotate(90);//
  474.    // matrix.postRotate(270);
  475.     // resize the bit map
  476.     matrix.postScale(scaleWidth, scaleHeight);
  477.  
  478.     // recreate the new Bitmap and set it back
  479.     Bitmap resizedBitmap = Bitmap.createBitmap(_bitmap, 0, 0,width, height, matrix, true);
  480.     _bitmap = resizedBitmap;
  481.  
  482.     Set this bitmap where you want to use..
  483. }
  484.  
  485. public String getPath(Uri uri) {
  486.     String[] projection = { MediaStore.Images.Media.DATA };
  487.     Cursor cursor = managedQuery(uri, projection, null, null, null);
  488.     if (cursor != null) {
  489.         // HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
  490.         // THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
  491.         int column_index = cursor
  492.                 .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  493.         cursor.moveToFirst();
  494.         return cursor.getString(column_index);
  495.     } else
  496.         return null;
  497. }