Problem trying to get the camera function and selecting a image from gallery to work? - Android Software Development

Hi still new to android, tried the following tutorial in the youtube link here https://www.youtube.com/watch?v=4LCnoVqQ6N4 but I couldn't get the app to work as I am unable to execute the camera on my physical phone where it kept giving me this popup "Something went Wrong while taking photos" when I press the camera imageview. And when I am at the gallery choosing a photo it will cause the app to suddenly stop.
Thus, I downloaded the author's source code here https://drive.google.com/file/d/0B2rvGRbu0A83cjBBZElhdGp5OHM/view but i also encounter the same issues stated above.
Tried adding the permission for camera,read,write external storage in the androidmanifest without any luck of solving it.
Error Log after i click on a image in the gallery:
Code:
08-17 12:21:08.181 17286-17286/com.example.user.cameratoserver E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.user.cameratoserver, PID: 17286
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=400, result=-1, data=Intent { dat=content://com.android.providers.media.documents/document/image:104460 flg=0x1 }} to activity {com.example.user.cameratoserver/com.example.user.cameratoserver.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=17286, uid=10038 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.app.ActivityThread.deliverResults(ActivityThread.java:3798)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3841)
at android.app.ActivityThread.access$1400(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:234)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=17286, uid=10038 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1627)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:427)
at android.content.ContentResolver.query(ContentResolver.java:497)
at android.content.ContentResolver.query(ContentResolver.java:439)
at com.kosalgeek.android.photoutil.RealPathUtil.getDataColumn(RealPathUtil.java:131)
at com.kosalgeek.android.photoutil.RealPathUtil.getRealPathFromURI_API19(RealPathUtil.java:62)
at com.kosalgeek.android.photoutil.GalleryPhoto.getPath(GalleryPhoto.java:49)
at com.example.user.cameratoserver.MainActivity.onActivityResult(MainActivity.java:100)
at android.app.Activity.dispatchActivityResult(Activity.java:6490)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3794)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3841)
at android.app.ActivityThread.access$1400(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:234)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

if you are testing on a device running android marshmallow and above you should also write code to request the android.permission.READ_EXTERNAL_STORAGE permission at runtime.
Take a look at the following link for android developers https://developer.android.com/training/permissions/requesting.html

nemoc 23 said:
if you are testing on a device running android marshmallow and above you should also write code to request the android.permission.READ_EXTERNAL_STORAGE permission at runtime.
Take a look at the following link for android developers https://developer.android.com/training/permissions/requesting.html
Click to expand...
Click to collapse
Oh i see but I've read the documentation but still at a lost as to how to implement the codes from the documentation into the source code in the link above, as this is my first android development experience was feeling rather lost.

imso said:
Oh i see but I've read the documentation but still at a lost as to how to implement the codes from the documentation into the source code in the link above, as this is my first android development experience was feeling rather lost.
Click to expand...
Click to collapse
If you are below MM you just need to add the permission to the manifest.
Code:
<manifest>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
If you are on MM or higher you need to add the permission the manifest and then ask for it at runtime.
Code:
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_CONTACTS) != PackageManager.READ_EXTERNAL_STORAGE) {
ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, CALLBACK_ID);
}
You will also need to handle the result of that on your activity:
Code:
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
if (requestCode == CALLBACK_ID) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Granted
} else {
// Not granted
}
}
}

Related

Camera Preview

Im trying to start a simple app and i need to display on a SurfaceView the preview of the cam as soon as the App start.
i added the permission to the manifest:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
and my code:
Code:
import android.content.Context;
import android.hardware.Camera;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MainActivity extends SurfaceView implements SurfaceHolder.Callback{
SurfaceView mSurfaceView;
private SurfaceHolder mHolder;
public Camera camera = null;
public MainActivity(Context context) {
super(context);
mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView);
mHolder = mSurfaceView.getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
[user=439709]@override[/user]
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
try{
camera.setPreviewDisplay(mHolder);
} catch(Exception e){
}
}
[user=439709]@override[/user]
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Camera.Parameters params = camera.getParameters();
params.setPreviewSize(width,height);
camera.setParameters(params);
camera.startPreview();
}
[user=439709]@override[/user]
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
camera = null;
}
}
Ive looked for many tutorial and all technically do the same or smiliart stuff. But the app crashes. I cant find a solution
LogCat
Code:
06-01 12:39:12.456 616-841/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.droidcam/.MainActivity bnds=[240,408][240,408]} from pid 861
06-01 12:39:12.596 616-841/system_process D/dalvikvm: GC_FOR_ALLOC freed 1352K, 16% free 11518K/13560K, paused 112ms, total 118ms
06-01 12:39:12.636 2744-2744/? D/dalvikvm: Late-enabling CheckJNI
06-01 12:39:12.646 616-881/system_process I/ActivityManager: Start proc com.example.droidcam for activity com.example.droidcam/.MainActivity: pid=2744 uid=10019 gids={50019, 1006, 1028}
06-01 12:39:12.746 2744-2744/com.example.droidcam E/Trace: error opening trace file: No such file or directory (2)
06-01 12:39:12.826 2744-2744/com.example.droidcam D/dalvikvm: newInstance failed: no <init>()
06-01 12:39:12.836 2744-2744/com.example.droidcam D/AndroidRuntime: Shutting down VM
06-01 12:39:12.836 2744-2744/com.example.droidcam W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x2b5d9930)
06-01 12:39:12.836 2744-2744/com.example.droidcam E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.droidcam/com.example.droidcam.MainActivity}: java.lang.InstantiationException: can't instantiate class com.example.droidcam.MainActivity; no empty constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2223)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5226)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.InstantiationException: can't instantiate class com.example.droidcam.MainActivity; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1319)
at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2214)
... 11 more
06-01 12:39:12.836 616-1341/system_process W/ActivityManager: Force finishing activity com.example.droidcam/.MainActivity
06-01 12:39:12.986 616-650/system_process D/dalvikvm: GC_FOR_ALLOC freed 1696K, 24% free 10472K/13772K, paused 76ms, total 77ms
06-01 12:39:13.387 616-647/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{2bd8aff0 u0 com.example.droidcam/.MainActivity}
06-01 12:39:18.952 2744-2744/? I/Process: Sending signal. PID: 2744 SIG: 9
06-01 12:39:18.952 616-943/system_process I/ActivityManager: Process com.example.droidcam (pid 2744) has died.
06-01 12:39:19.002 616-616/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected]
Please put your code into code tags.
EDIT: Thanks.
and Post/check logcats.
just saying it crashes is too vague.
out of ideas said:
and Post/check logcats.
just saying it crashes is too vague.
Click to expand...
Click to collapse
On Eclipse i know how to show the windows of the LogCat, but cant really find it here on Android Studio.
Im a bit newby about this sorry, coming from PHP using just Notepad.
Guess i found it, added log cat
I saw some tutorial like this, im not sure why it doesnt start.
Is it for te onCreate method missing? but i saw that for other works anyway like this
Btw i've also triyed an other way, but stills give me errors. i could upload that one too, different logcat.
Hope one of the two could be solved
Code:
import android.app.Activity;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
public class MainActivity extends Activity implements SurfaceHolder.Callback{
/* VARIABILI PRIVATE */
private SurfaceView mSurfaceView;
private SurfaceHolder mSurfaceHolder;
private Camera mCamera;
/** Called when the activity is first created. */
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSurfaceView = (SurfaceView)findViewById(R.id.surfaceView);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
[user=439709]@override[/user]
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
Camera.Parameters params = mCamera.getParameters();
params.setPreviewSize(arg2, arg3);
mCamera.setParameters(params);
try {
//lancio la preview
mCamera.setPreviewDisplay(arg0);
mCamera.startPreview();
} catch (IOException e) {
//gestione errore
}
}
[user=439709]@override[/user]
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
}
[user=439709]@override[/user]
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
}
logcat
Code:
06-01 13:32:31.187 616-661/system_process I/ActivityManager: Start proc com.android.vending for service com.android.vending/com.google.android.finsky.services.ContentSyncService: pid=25552 uid=10005 gids={50005, 3003, 1015, 1028}
06-01 13:32:31.227 25552-25552/com.android.vending E/Trace: error opening trace file: No such file or directory (2)
06-01 13:32:31.387 616-841/system_process I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.droidcam/.MainActivity bnds=[240,408][240,408]} from pid 861
06-01 13:32:31.437 25566-25566/? D/dalvikvm: Late-enabling CheckJNI
06-01 13:32:31.447 616-1341/system_process I/ActivityManager: Start proc com.example.droidcam for activity com.example.droidcam/.MainActivity: pid=25566 uid=10019 gids={50019, 1006, 1028}
06-01 13:32:31.607 25566-25566/com.example.droidcam E/Trace: error opening trace file: No such file or directory (2)
06-01 13:32:31.787 25552-25552/com.android.vending D/Finsky: [1] FinskyApp.onCreate: Initializing network with DFE https://android.clients.google.com/fdfe/
06-01 13:32:31.987 25552-25552/com.android.vending D/Finsky: [1] DailyHygiene.goMakeHygieneIfDirty: No need to run daily hygiene.
06-01 13:32:32.037 25552-25552/com.android.vending W/Settings: Setting download_manager_max_bytes_over_mobile has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
06-01 13:32:32.037 25552-25552/com.android.vending W/Settings: Setting download_manager_recommended_max_bytes_over_mobile has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
06-01 13:32:32.178 616-881/system_process D/dalvikvm: GC_FOR_ALLOC freed 656K, 26% free 11321K/15124K, paused 82ms, total 86ms
06-01 13:32:32.238 25566-25566/com.example.droidcam D/libEGL: loaded /system/lib/egl/libEGL_adreno200.so
06-01 13:32:32.258 25566-25566/com.example.droidcam D/libEGL: loaded /system/lib/egl/libGLESv1_CM_adreno200.so
06-01 13:32:32.258 25566-25566/com.example.droidcam D/libEGL: loaded /system/lib/egl/libGLESv2_adreno200.so
06-01 13:32:32.268 25566-25566/com.example.droidcam I/Adreno200-EGL: <qeglDrvAPI_eglInitialize:294>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_JB.04.01.01.00.036_msm8960_JB_CL2644550_release_AU (CL2644550)
Build Date: 07/31/12 Tue
Local Branch:
Remote Branch: quic/master
Local Patches: NONE
Reconstruct Branch: AU_LINUX_ANDROID_JB.04.01.01.00.036 + NOTHING
06-01 13:32:32.318 25566-25566/com.example.droidcam D/OpenGLRenderer: Enabling debug mode 0
06-01 13:32:32.348 256-515/? I/AwesomePlayer: setDataSource_l(URL suppressed)
06-01 13:32:32.378 256-25622/? D/MediaExtractor: returning default extractor
06-01 13:32:32.388 256-515/? I/AwesomePlayer: setDataSource_l(URL suppressed)
06-01 13:32:32.408 256-25626/? D/MediaExtractor: returning default extractor
06-01 13:32:32.408 256-515/? I/CameraClient: Opening camera 0
06-01 13:32:32.408 256-515/? W/ServiceManager: Permission failure: com.sonyericsson.permission.CAMERA_EXTENDED from uid=10019 pid=25566
06-01 13:32:32.438 256-25630/? I/caladbolg: 3348999538 cald_camctrl.c (6713) 25630 P [SVR] -945967758 + Cald_CamCtrl_PowerUp
06-01 13:32:32.438 256-25630/? I/caladbolg: 3348999630 cald_camctrl.c (7484) 25630 P [SVR] -945967666 + Cald_CamCtrl_FSM_Func_PowerUp
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349003170 cald_hal_qct.c (2789) 25630 P [HAL] -945964126 + Cald_Hal_Qct_If_PowerUp
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349003323 cald_hal_qct.c (2847) 25630 P [HAL] -945963973 - Cald_Hal_Qct_If_PowerUp (0)
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349004665 cald_camctrl.c (7563) 25630 P [SVR] -945962631 - Cald_CamCtrl_FSM_Func_PowerUp (0)
06-01 13:32:32.438 256-25630/? I/caladbolg: 3349004726 cald_camctrl.c (6720) 25630 P [SVR] -945962570 - Cald_CamCtrl_PowerUp (0)
06-01 13:32:32.448 256-25630/? E/caladbolg: 3349014431 cald_camctrl.c (11888) 25630 E [SVR] PreviewSize Invalid param: value[402x527]
06-01 13:32:32.458 25566-25566/com.example.droidcam D/AndroidRuntime: Shutting down VM
06-01 13:32:32.458 25566-25566/com.example.droidcam W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x2b5d9930)
06-01 13:32:32.488 25566-25566/com.example.droidcam E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1496)
at com.example.droidcam.MainActivity.surfaceChanged(MainActivity.java:41)
at android.view.SurfaceView.updateWindow(SurfaceView.java:580)
at android.view.SurfaceView.access$000(SurfaceView.java:86)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:174)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:680)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1842)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5226)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
06-01 13:32:32.498 616-943/system_process W/ActivityManager: Force finishing activity com.example.droidcam/.MainActivity
06-01 13:32:32.688 25552-25552/com.android.vending D/Finsky: [1] 2.run: Loaded library for account: [i1YaFxIWaZrcOQ26zxNX5K0RvvY]
06-01 13:32:32.688 25552-25552/com.android.vending D/Finsky: [1] 2.run: Finished loading 1 libraries.
06-01 13:32:32.908 25552-25552/com.android.vending D/Finsky: [1] 5.onFinished: Installation state replication succeeded.
06-01 13:32:33.018 616-647/system_process W/ActivityManager: Activity pause timeout for ActivityRecord{2b946870 u0 com.example.droidcam/.MainActivity}
In Android you normally do not use the constructor of an Activity for anything.
Use the onCreate method instead.
EDIT: The log says that the constructor must be empty.
nikwen said:
In Android you normally do not use the constructor of an Activity for anything.
Use the onCreate method instead.
EDIT: The log says that the constructor must be empty.
Click to expand...
Click to collapse
I thought about that (even if i saw video tutorial doing it) so i tried wht onCreate method and now it seams to give problem with the setParameters?
Ive uploaded the new code and logcats before
Ah. Check this: http://stackoverflow.com/questions/3890381/camera-setparameters-failed-in-android
nikwen said:
Ah. Check this: http://stackoverflow.com/questions/3890381/camera-setparameters-failed-in-android
Click to expand...
Click to collapse
i tryed that at th beggin, and didnt work, in fact i tried it again and still give me the same error apparently
While I'm still learning myself, it looks like you are getting a failed camera permission. And then it tries to pass in an invalid parameter to the camera.
deniel said:
I/CameraClient: Opening camera 0
06-01 13:32:32.408 256-515/? W/ServiceManager: Permission failure: com.sonyericsson.permission.CAMERA_EXTENDED from uid=10019 pid=25566
06-01 13:32:32.448 256-25630/? E/caladbolg: 3349014431 cald_camctrl.c (11888) 25630 E [SVR] PreviewSize Invalid param: value[402x527]
[/CODE]
Click to expand...
Click to collapse
Sent from a Toasted Devil
netwokz said:
While I'm still learning myself, it looks like you are getting a failed camera permission. And then it tries to pass in an invalid parameter to the camera.
Sent from a Toasted Devil
Click to expand...
Click to collapse
But cant understand which one and how should i do. it ryed the 2 ways everybody does
What phone are you trying this on? Have you tried it in an emulator?
After getting home and I was able to try your second piece of code. It looks like it is a problem with <CODE>params.setPreviewSize(arg2, arg3);</CODE>, it doesn't like the width and height arguments. I found THIS(second answer). and after plugging it into your code it was working for me. If you like I can show you the modified code, altho its real easy to plug in.
netwokz said:
After getting home and I was able to try your second piece of code. It looks like it is a problem with <CODE>params.setPreviewSize(arg2, arg3);</CODE>, it doesn't like the width and height arguments. I found THIS(second answer). and after plugging it into your code it was working for me. If you like I can show you the modified code, altho its real easy to plug in.
Click to expand...
Click to collapse
i tryed his first example and finally i get his "distoted" image. When i'll have time ill try the rets thnk u very much
ill try this:
Code:
Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters) {
Camera.Size result=null;
float dr = Float.MAX_VALUE;
float ratio = (float)width/(float)height;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
float r = (float)size.width/(float)size.height;
if( Math.abs(r - ratio) < dr && size.width <= width && size.height <= height ) {
dr = Math.abs(r - ratio);
result = size;
}
}
return result;
}
Code:
ublic void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
if (isPreviewRunning) {
mCamera.stopPreview();
}
Camera.Parameters parameters = mCamera.getParameters();
List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = getBestPreviewSize( w, h, parameters);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
mCamera.setParameters(parameters);
mCamera.startPreview();
isPreviewRunning =true;
}
im not sure abot the 3rd parameter of the getBestPreviewSize method which one is it. Like this is still distorted
Yeah, I could never fix the distortion back when I was trying my camera app. But I think I will tinker with it again. Keep this updated if you find anything, I will also.
Sent from a Toasted Devil

[GUIDE] Working with Parse | Push notifications | Users | Saving data | More

Hey guys!
I know most of you have never heard of this, but there's a organisation that provides many useful things to use in your app!
It's called "Parse"
Now, I will guide you trough the use of Parse, beginning with Parse Push. Let's get started, shall we?
Section 1:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Okay, so Parse Push is a "library" or service that makes it A LOT easier to send push notifications to the users of your app. I had searched for months on how to send push notifications, but I just never succeeded (And I can't afford a proper server ). But that's where Parse Push comes in!
The first thing you'll have to do to setup Parse Push is download and install the Parse SDK. This is how:
Step 1: Make an account at Parse.com and setup the app you want to include Parse in.
Step 2: Download the SDK: https://parse.com/downloads/android/Parse/latest
Step 3: Unzip it into a random folder
Step 4: Copy all the files in your projects "lib" folder. If your project doesn't have one, simply make one in the root of your directory (e.g /MyApp/lib/)
Step 5: Call the "initialize" method in your onCreate method, like this:
Code:
Parse.initialize(this, "Your application ID", "Your client key");
NOTE: You can find you application ID and client key here: https://parse.com/apps/YOUR-APP'S-NAME/edit#app_keys
NOTE: Be sure you also imported these calls:
Code:
import com.parse.Parse;
import com.parse.ParseAnalytics;
Step 6: Your app needs the android.permission.INTERNET and android.permission.ACCESS_NETWORK_STATE permission to work with Parse, so add these lines in your AndroidManifest.xml file, right before the <application> tag:
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Also, add this between the <application> and </application> tag:
Code:
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
Step 7: Place this code in your onCreate method to track how many times your app has been opened:
Code:
ParseAnalytics.trackAppOpened(getIntent());
Step 8: It's testing time!
To test if your app has been setup the right way, add this code to your onCreate method:
Code:
ParseObject object = new ParseObject("TestObject");
object.put("name", "testname");
object.saveInBackground();
And run your app!
Step 9: Get your data trough a web browser! Go to this site: https://parse.com/apps/YOUR-APP'S-NAME/collections
Then it should say something like: TestObject (1), with the name testname
Step 10: Send a push notification: Goto https://parse.com/apps/YOUR-APP'S-NAME/push_notifications and click on + Send a push
Type in your message, hit Send notification at the bottom and your app will get a push notification!
That's it! You have now setup your app to receive push notifications
Okay, here we go, the next section
Section 2: Parse Users
So, the ParseUser class is a really useful thingy for people who want to have some more control over the people who use their apps.
You can (for example) set a username, and then when the user wants to post something in the app, instead of him having to type his name all over again, the app can just use the ParseUser.getCurrentUser().getUsername() method, and it will automatigally get the user's name for him!
Now I'll show you how to setup a ParseUser:
Step 1: Setup everything in the same way as you did in Section 1
Step 2: First we'll have to make a ParseUser, by signing up. Here's a quick signing up code snippet:
Code:
ParseUser signup = new ParseUser();
signup.setUsername("testuser");
signup.setPassword("testpassword");
signup.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
// The user also is logged in now :)
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
// Mostly the problem is that the username is already taken
}
But, ofcourse the user wants to choose his own username and password. For that you can use an EditText:
Code:
EditText username = (EditText) findViewById(R.id.USERNAMEEDITTEXTiD);
EditText password = (EditText) findViewById(R.id.PASSWORDEDITTEXTiD);
ParseUser signup = new ParseUser();
signup.setUsername(username.getText().toString());
signup.setPassword(password.getText().toString());
signup.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
// The user also is logged in now :)
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
// Mostly the problem is that the username is already taken
}
But, if the user didn't type in anything, signin up throws a IllegalArgumentException. You can avoid that by using try and catch claws, like in this example:
Code:
EditText username = (EditText) findViewById(R.id.USERNAMEEDITTEXTiD);
EditText password = (EditText) findViewById(R.id.PASSWORDEDITTEXTiD);
try {
ParseUser signup = new ParseUser();
signup.setUsername(username.getText().toString());
signup.setPassword(password.getText().toString());
signup.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
// The user also is logged in now :)
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
// Mostly the problem is that the username is already taken
}
} catch (IllegalArgumentException IO {
// The user didn't type in anything, I suggest using a Toast to notify him
}
Now, if a user wants to post something using his account name, you can get his username using this:
Code:
ParseUser currentUser = ParseUser.getCurrentUser();
currentUser.getUsername();
If your user wants to login, you can use this:
Code:
EditText username = (EditText) findViewById(R.id.USERNAMEEDITTEXT);
EditText password = (EditText) findViewById(R.id.PASSWORDEDITTEXT);
ParseUser.logInInBackground(username.getText().toString(), password .getText().toString(), new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// Hooray! The user is logged in.
} else {
// Signup failed. Look at the ParseException to see what happened.
// The main cause is that the user didn't type in a correct username or password
}
}
});
And if you want to log the user out, you can do it very simply by calling:
Code:
ParseUser.logOut();
And that's it! You just learned how to signup a user, log him in, get his username and log him out!
Now it's time for the next section!
Time for section 3!
Section 3: Parse Data
Huh, what is Parse Data? Well, that's a good question sir! P) Parse Data will let you save ParseObjects into the Parse Cloud. That will allow you to store all of your data, and if you want you can read it back too! This could be useful for games with highscores, forum apps and more! Another great part of Parse!
Let's start with saving a ParseObject to the cloud, shall we?
Step 1: Setup your app the same way you did in Section 1
Step 2: We'll start with a really simple ParseObject, for now it's going to be called "testObject"
Here's a quick example for a ParseObject that will save to the cloud:
Code:
ParseObject testObject= new ParseObject("testObject");
testObject.put("name", "TestObject's name");
testObject.put("random",true);
testObject.put("someint", 1337);
testObject.saveInBackground();
As you can see, we can put everything we want in it (e.g. testObject.put("ASDASDASDA", "ASDASDASD")
They don't always have to be strings, they can be booleans, ints, strings, JSON objects, java.util.Date, byte[] or ParseObjects(That's right, you can save a ParseObject inside a ParseObject )
You can also wait for the user untill he has an internet connection, and when he finally has, save the object:
Code:
ParseObject testObject= new ParseObject("testObject");
testObject.put("name", "TestObject's name");
testObject.put("random",true);
testObject.put("someint", 1337);
testObject.saveEventually();
For retreiving the object, you can do something like this:
Code:
ParseQuery<ParseObject> query = ParseQuery.getQuery("testObject");
query.getInBackground("YOUROBJECTID", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// everything went okay :D
} else {
// something went wrong D:
}
}
})
Updating a ParseObject is really simple, just use the same as you did before, but with new data in the testObject.put("somedata", "the data"); section
Deleting it is farely simple as well, just use this:
Code:
testObject.deleteInBackground();
You can also delete just one field:
Code:
testObject.remove("name");
testObject.saveInBackground();
And that's it for now!
And again, mine
Last one
This really is the last one!
Wow! Great. :good:
Thanks.
How much is the 1 GB per month which you get for free?
EDIT: Saw that this is the storage. You get 1,000,000 notifications for free.
nikwen said:
Wow! Great. :good:
Thanks.
How much is the 1 GB per month which you get for free?
Click to expand...
Click to collapse
Well it's really good, as 100 push notifications is just 0.1 % of the whole 1 GB
So, it's enough for me
MaartenXDA said:
Well it's really good, as 100 push notifications is just 0.1 % of the whole 1 GB
So, it's enough for me
Click to expand...
Click to collapse
10 kB per message? Sounds good. Thanks.
ParseUsers section updated!
Ok. Just saw that you get 1,000,000 messages for free.
That is great for small apps but if you go beyond that, it will be very expensive. However, I cannot compare it to the price of a server.
Any experiences?
nikwen said:
Ok. Just saw that you get 1,000,000 messages for free.
That is great for small apps but if you go beyond that, it will be very expensive. However, I cannot compare it to the price of a server.
Any experiences?
Click to expand...
Click to collapse
Yeah, well, the internet keeps getting more and more expensive. I don't like it either, but my app isn't that big so I can live with it
ParseData section updated!
Good job Maarten! So this is your method..! xD
Keep it up!
xpirt
help needed
Code:
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()){
case R.id.bgo2:
try{
username=et1.getText().toString();
password=et2.getText().toString();
ParseUser signup = new ParseUser();
signup.setUsername(username);
signup.setPassword(password);
signup.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
Intent i = new Intent(MainActivity.this,Slider.class);
startActivity(i);
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
Toast.makeText(MainActivity.this, "something wrong" , Toast.LENGTH_SHORT).show();
}
}
});
} catch (IllegalArgumentException IO) {
// The user didn't type in anything, I suggest using a Toast to notify him
Toast.makeText(MainActivity.this, "Please type something" , Toast.LENGTH_SHORT).show();
}
this is my code for signup on click of a button. everything is setup. but nothing happens when i click on sighn up button. and when i click on sigh in.. the app exits with an error. logcat says:-
Code:
06-03 11:55:41.761: E/SpannableStringBuilder(15340): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 11:55:41.761: E/SpannableStringBuilder(15340): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 11:55:42.178: E/NativeCrypto(15340): ssl=0x52f7c578 cert_verify_callback x509_store_ctx=0x52112a80 arg=0x0
06-03 11:55:42.178: E/NativeCrypto(15340): ssl=0x52f7c578 cert_verify_callback calling verifyCertificateChain authMethod=RSA
06-03 11:55:50.001: E/AndroidRuntime(15340): FATAL EXCEPTION: main
06-03 11:55:50.001: E/AndroidRuntime(15340): java.lang.IllegalArgumentException: Must specify a username for the user to log in with
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.parse.ParseUser.logInAsync(ParseUser.java:655)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.parse.ParseUser.logInInBackground(ParseUser.java:715)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.sandy.letsfixthat.MainActivity.onClick(MainActivity.java:98)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.view.View.performClick(View.java:4091)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.view.View$PerformClick.run(View.java:17072)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.os.Handler.handleCallback(Handler.java:615)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.os.Handler.dispatchMessage(Handler.java:92)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.os.Looper.loop(Looper.java:153)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.app.ActivityThread.main(ActivityThread.java:5086)
06-03 11:55:50.001: E/AndroidRuntime(15340): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 11:55:50.001: E/AndroidRuntime(15340): at java.lang.reflect.Method.invoke(Method.java:511)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-03 11:55:50.001: E/AndroidRuntime(15340): at dalvik.system.NativeStart.main(Native Method)
06-03 11:55:56.435: E/Trace(15377): error opening trace file: No such file or directory (2)
06-03 11:55:56.452: E/com.parse.PushService(15377): The Parse push service cannot start because Parse.initialize has not yet been called.
If you call Parse.initialize from an Activity's onCreate, that call should instead be in the Application.onCreate.
Be sure your Application class is registered in your AndroidManifest.xml with the android:name property of your <application> tag.
push notification working fine for me.
Sandy||Striker said:
Code:
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()){
case R.id.bgo2:
try{
username=et1.getText().toString();
password=et2.getText().toString();
ParseUser signup = new ParseUser();
signup.setUsername(username);
signup.setPassword(password);
signup.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
Intent i = new Intent(MainActivity.this,Slider.class);
startActivity(i);
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
Toast.makeText(MainActivity.this, "something wrong" , Toast.LENGTH_SHORT).show();
}
}
});
} catch (IllegalArgumentException IO) {
// The user didn't type in anything, I suggest using a Toast to notify him
Toast.makeText(MainActivity.this, "Please type something" , Toast.LENGTH_SHORT).show();
}
this is my code for signup on click of a button. everything is setup. but nothing happens when i click on sighn up button. and when i click on sigh in.. the app exits with an error. logcat says:-
Code:
06-03 11:55:41.761: E/SpannableStringBuilder(15340): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 11:55:41.761: E/SpannableStringBuilder(15340): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 11:55:42.178: E/NativeCrypto(15340): ssl=0x52f7c578 cert_verify_callback x509_store_ctx=0x52112a80 arg=0x0
06-03 11:55:42.178: E/NativeCrypto(15340): ssl=0x52f7c578 cert_verify_callback calling verifyCertificateChain authMethod=RSA
06-03 11:55:50.001: E/AndroidRuntime(15340): FATAL EXCEPTION: main
06-03 11:55:50.001: E/AndroidRuntime(15340): java.lang.IllegalArgumentException: Must specify a username for the user to log in with
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.parse.ParseUser.logInAsync(ParseUser.java:655)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.parse.ParseUser.logInInBackground(ParseUser.java:715)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.sandy.letsfixthat.MainActivity.onClick(MainActivity.java:98)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.view.View.performClick(View.java:4091)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.view.View$PerformClick.run(View.java:17072)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.os.Handler.handleCallback(Handler.java:615)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.os.Handler.dispatchMessage(Handler.java:92)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.os.Looper.loop(Looper.java:153)
06-03 11:55:50.001: E/AndroidRuntime(15340): at android.app.ActivityThread.main(ActivityThread.java:5086)
06-03 11:55:50.001: E/AndroidRuntime(15340): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 11:55:50.001: E/AndroidRuntime(15340): at java.lang.reflect.Method.invoke(Method.java:511)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
06-03 11:55:50.001: E/AndroidRuntime(15340): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-03 11:55:50.001: E/AndroidRuntime(15340): at dalvik.system.NativeStart.main(Native Method)
06-03 11:55:56.435: E/Trace(15377): error opening trace file: No such file or directory (2)
06-03 11:55:56.452: E/com.parse.PushService(15377): The Parse push service cannot start because Parse.initialize has not yet been called.
If you call Parse.initialize from an Activity's onCreate, that call should instead be in the Application.onCreate.
Be sure your Application class is registered in your AndroidManifest.xml with the android:name property of your <application> tag.
push notification working fine for me.
Click to expand...
Click to collapse
I think that the EditText for the username is empty.
Quote from second post:
But, if the user didn't type in anything, signin up throws a IllegalArgumentException.
Click to expand...
Click to collapse
nikwen said:
I think that the EditText for the username is empty.
Quote from second post:
Click to expand...
Click to collapse
no its not empty.. i tried with a few entries.. it is not signing up users??
the above code is for signing the new users
Sandy||Striker said:
no its not empty.. i tried with a few entries.. it is not signing up users??
the above code is for signing the new users
Click to expand...
Click to collapse
Just checked the logs again. They contain instructions to get it working:
The Parse push service cannot start because Parse.initialize has not yet been called.
If you call Parse.initialize from an Activity's onCreate, that call should instead be in the Application.onCreate.
Be sure your Application class is registered in your AndroidManifest.xml with the android:name property of your <application> tag.
Click to expand...
Click to collapse
@nikwen
this is the error now
i am getting this on clicking signup button
Code:
06-03 12:12:51.893: E/SpannableStringBuilder(22529): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 12:12:51.893: E/SpannableStringBuilder(22529): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 12:12:59.150: E/AndroidRuntime(22529): FATAL EXCEPTION: main
06-03 12:12:59.150: E/AndroidRuntime(22529): java.lang.NullPointerException
06-03 12:12:59.150: E/AndroidRuntime(22529): at com.sandy.letsfixthat.MainActivity.onClick(MainActivity.java:55)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.view.View.performClick(View.java:4091)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.view.View$PerformClick.run(View.java:17072)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.os.Handler.handleCallback(Handler.java:615)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.os.Handler.dispatchMessage(Handler.java:92)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.os.Looper.loop(Looper.java:153)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.app.ActivityThread.main(ActivityThread.java:5086)
06-03 12:12:59.150: E/AndroidRuntime(22529): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 12:12:59.150: E/AndroidRuntime(22529): at java.lang.reflect.Method.invoke(Method.java:511)
06-03 12:12:59.150: E/AndroidRuntime(22529): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
06-03 12:12:59.150: E/AndroidRuntime(22529): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-03 12:12:59.150: E/AndroidRuntime(22529): at dalvik.system.NativeStart.main(Native Method)
Sandy||Striker said:
@nikwen
this is the error now
i am getting this on clicking signup button
Code:
06-03 12:12:51.893: E/SpannableStringBuilder(22529): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 12:12:51.893: E/SpannableStringBuilder(22529): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
06-03 12:12:59.150: E/AndroidRuntime(22529): FATAL EXCEPTION: main
06-03 12:12:59.150: E/AndroidRuntime(22529): java.lang.NullPointerException
06-03 12:12:59.150: E/AndroidRuntime(22529): at com.sandy.letsfixthat.MainActivity.onClick(MainActivity.java:55)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.view.View.performClick(View.java:4091)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.view.View$PerformClick.run(View.java:17072)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.os.Handler.handleCallback(Handler.java:615)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.os.Handler.dispatchMessage(Handler.java:92)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.os.Looper.loop(Looper.java:153)
06-03 12:12:59.150: E/AndroidRuntime(22529): at android.app.ActivityThread.main(ActivityThread.java:5086)
06-03 12:12:59.150: E/AndroidRuntime(22529): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 12:12:59.150: E/AndroidRuntime(22529): at java.lang.reflect.Method.invoke(Method.java:511)
06-03 12:12:59.150: E/AndroidRuntime(22529): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
06-03 12:12:59.150: E/AndroidRuntime(22529): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
06-03 12:12:59.150: E/AndroidRuntime(22529): at dalvik.system.NativeStart.main(Native Method)
Click to expand...
Click to collapse
The error is in line 55 in MainActivity.java.
Could you please highlight this line?
nikwen said:
The error is in line 55 in MainActivity.java.
Could you please highlight this line?
Click to expand...
Click to collapse
Code:
password=et2.getText().toString();
---------- Post added at 12:58 PM ---------- Previous post was at 12:45 PM ----------
got the error.. thanks for your help

JNI_Onload returned bad version

Hi Guys,
I am trying to load a third party .so file for which I do not have the source code. I call loadlibrary like this:
Code:
try
{
System.loadLibrary("3rdpartyjni");
}
catch (Exception e)
{
System.err.println("We have a problem" + e);
}
It immediately fails with the following error:
07-17 10:23:39.484: W/dalvikvm(1540): JNI_OnLoad returned bad version (-1) in 3rdpartyini 0x40ce70b0
07-17 10:23:39.484: W/dalvikvm(1540): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
The exception catch code, by the way, is not fired. The app just crashes. I don't even need this to work in the real world - I need to run a function in this 3rd party .so exactly 1 time. I just need it to work in the emulator. Is there a way to get it to ignore the error and let me use the library?

[Q] what the correct way to use ShowcaseView?

when I try to use ShowcaseView I get error
Code:
@override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final ImageButton saveButton = (ImageButton) view.findViewById(R.id.button_Save);
ViewTarget viewTarget = new ViewTarget(saveButton);
showcaseView = new ShowcaseView.Builder(getActivity())
.setTarget(viewTarget)
.setContentTitle("Reset Button")
.setContentText("This will erase all the data in the table except the line that in progress")
.build();
}
when I tried to do the same thing in my fragmentactivity and didn't work, but when I did the same thing but took a view that declared in the fragmentactivity and not in the fragment it worked.
Logcat:
Code:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:724)
at android.graphics.Bitmap.createBitmap(Bitmap.java:703)
at android.graphics.Bitmap.createBitmap(Bitmap.java:670)
at com.github.amlcurran.showcaseview.ShowcaseView.updateBitmap(ShowcaseView.java:169)
at com.github.amlcurran.showcaseview.ShowcaseView.onGlobalLayout(ShowcaseView.java:343)
at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:839)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2050)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
I understand what the error said but how can I fix it?

[Q] [Android Wear] Displaying a Google Map on a watch

Hello, i'm trying to display a Google map on my Sony SmartWatch3.
In my wear layout, i'm using a MapFragment with this code :
Code:
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mapFragment"
class="com.google.android.gms.maps.MapFragment"/>
My wear main activity implements OnMapReadyCallback :
Code:
@Override
public void onMapReady(GoogleMap map) {
SupportMapFragment fragment = ( SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapFragment);
// Getting Google Map
GoogleMap googleMap = fragment.getMap();
Finally, i've got this error :
Code:
02-03 16:44:23.456 2377-2377/com.example.andy.myfirstwearablemapapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.andy.myfirstwearablemapapplication, PID: 2377
android.view.InflateException: Binary XML file line #7: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:179)
at android.support.wearable.view.WatchViewStub.onApplyWindowInsets(WatchViewStub.java:148)
at android.view.View.dispatchApplyWindowInsets(View.java:6514)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5782)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchApplyWindowInsets(PhoneWindow.java:2335)
at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1205)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1423)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.IllegalStateException: Unable to find dynamic class com.google.android.gms.maps.internal.CreatorImpl
at com.google.android.gms.maps.internal.x.a(Unknown Source)
at com.google.android.gms.maps.internal.x.U(Unknown Source)
at com.google.android.gms.maps.internal.x.S(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.nO(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2115)
at android.app.Activity.onCreateView(Activity.java:5282)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:179)
at android.support.wearable.view.WatchViewStub.onApplyWindowInsets(WatchViewStub.java:148)
at android.view.View.dispatchApplyWindowInsets(View.java:6514)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5782)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchApplyWindowInsets(PhoneWindow.java:2335)
at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1205)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1423)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Is it really possible to display a map on a watch ? If yes, can you tell me how ?
Thanks in advance
I think that the Google Play Services on Android Wear doesn't have the Map API so java.lang.IllegalStateException was thrown. So no, you can't use the Map API directly on Wear devices
Thanks for your answer
saothoi said:
I think that the Google Play Services on Android Wear doesn't have the Map API so java.lang.IllegalStateException was thrown. So no, you can't use the Map API directly on Wear devices
Click to expand...
Click to collapse
Look at this
https://play.google.com/store/apps/details?id=net.dheera.wearmaps&hl=nl_NL
Thanks for your answer. This application uses Google Maps Static API and apparently, the number of recovered images is limited :/
Can't you make an handled app that uses google map, with wear app synchronizing the displayed picture?

Categories

Resources