Android App aborts while sending receiving LinkedHashmap between activity - Java for Android App Development

I want to send and receive LinkedHashmap between activities. Below is my CODE but the application aborts when I try to pass/retrieve the map. Could anyone please help?
============
Sending Activity
============
HTML:
package com.moodswings.moodchart;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.*;
public class MainActivity extends Activity
{
ScrollView sv;
TableLayout myTableLayout;
Button submitButton;
Button resetButton;
LinkedHashMap<String, List<EditText>> dataMap = new LinkedHashMap<String, List<EditText>>();
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sv = new ScrollView(this);
myTableLayout = new TableLayout (this);
submitButton = new Button(this);
resetButton = new Button(this);
drawScreen();
addListenerOnButton();
}
public void drawScreen()
{
String[] fctrdList = {"Mood","Aggr","Axty"};//,"Depr","Obsv", "Sleep"};
myTableLayout.removeAllViews();
sv.removeAllViews();
//myTableLayout.setBackgroundResource(R.drawable.background);
// rows
TableRow hrsRow = new TableRow(this);
TableRow buttonRow = new TableRow(this);
// margins
hrsRow.setPadding( 20,10,20,10);
// the buttons table layout
// purpose : right align for both buttons
TableLayout buttonsLayout = new TableLayout(this);
buttonRow.setPadding(20,50,40,0);
// the submit and reset buttons
submitButton.setText( "Submit");
resetButton.setText( "Reset");
buttonRow.addView( submitButton);
buttonRow.addView(resetButton);
buttonRow.setGravity(Gravity.RIGHT);
buttonsLayout.addView(buttonRow);
myTableLayout.addView(buttonsLayout);
//=============================================================
// time
TextView hrsV = new TextView(this);
hrsV.setText( "[00-04] [04-08] [08-12] [12-16] [16-20] [20-00]" );
hrsV.setTextSize(10);
hrsV.setTextColor(Color.BLACK );
hrsV.setGravity(Gravity.CENTER_HORIZONTAL);
hrsRow.addView(hrsV);
hrsRow.setGravity(Gravity.CENTER);
// the hours tablelayout
TableLayout hrsTableLayout = new TableLayout(this);
hrsTableLayout.addView(hrsRow);
// add the hours layout to the main one
myTableLayout.addView(hrsTableLayout);
/// the input rows
for(int j = 0; j < fctrdList.length; j++)
{
inputRow(myTableLayout, fctrdList[j]);
}
//
sv.addView(myTableLayout);
// set the screen content to table layout's
setContentView(sv);
}
public void inputRow( TableLayout tl, String label )
{
TableRow inputRow = new TableRow(this);
TextView tv = new TextView(this);
List<EditText> dataList = new ArrayList<EditText>();
// some margin
inputRow.setPadding(10,0,10,0);
tv.setText(label);
tv.setTextSize(10);
inputRow.addView(tv);
for(int i = 0; i < 2; i++)
{
EditText edit = new EditText(this);
edit.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
edit.setWidth(50);
edit.setHeight(50);
edit.setFilters(new InputFilter[] {new InputFilter.LengthFilter(2)});
edit.setInputType(InputType.TYPE_CLASS_NUMBER);
//edit.setId( 1 );
edit.setGravity(Gravity.LEFT);
inputRow.addView(edit);
dataList.add(edit);
}
dataMap.put(label, dataList);
tl.addView(inputRow);
}
public void addListenerOnButton() {
submitButton.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View arg0) {
LinkedHashMap<String, List<String>> moodMap = new LinkedHashMap<String, List<String>>();
// populate List with EditText contents
for (LinkedHashMap.Entry<String, List<EditText>> entry : dataMap.entrySet()) {
List<EditText> edValues = entry.getValue();
//System.out.println("edValues size :" + edValues.size());
List<String> scaleList = new ArrayList<String>();
for(int a = 0; a < edValues.size(); a++)
{
EditText t = edValues.get(a);
String text = t.getText().toString();
//System.out.println("====== EditText :" + text);
scaleList.add(text);
}
moodMap.put(entry.getKey(), scaleList);
}
// =================
Bundle bundle = new Bundle();
bundle.putSerializable("factorsDataMap", moodMap);
Intent intent = new Intent(MainActivity.this, MoodSummary.class);
intent.putExtras(bundle);
startActivity(intent);
// =================
/*Intent intent = new Intent(MainActivity.this, MoodSummary.class);
intent.putExtra("map", moodMap);
startActivity(intent);*/
//==================
}
});
}
}
============
Second Activity
============
HTML:
package com.moodswings.moodchart;
import java.util.LinkedHashMap;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class MoodSummary extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mood_summary);
System.out.println("HashMapTest");
LinkedHashMap<String, List<String>> moodLnkMap = new LinkedHashMap<String, List<String>>();
Bundle bundle = this.getIntent().getExtras();
if(bundle != null){
moodLnkMap = (LinkedHashMap<String, List<String>>) bundle.getSerializable("factorsDataMap");
if(moodLnkMap.size() != 0)
{
System.out.println("moodMap size: " + moodLnkMap.size());
}
else
{
System.out.println("moodMap size: 0");
}
}
}
}
========
The Logcat
========
HTML:
01-22 17:58:16.345: D/MediaScannerService(198): done scanning volume internal 01-22 17:58:17.024: D/dalvikvm(116): GC_EXTERNAL_ALLOC freed 11169 objects / 521416 bytes in 81ms 01-22 17:58:17.294: D/dalvikvm(116): GC_EXPLICIT freed 1737 objects / 96240 bytes in 63ms 01-22 17:58:17.404: D/PackageParser(58): Scanning package: /data/app/vmdl52647.tmp 01-22 17:58:17.655: I/PackageManager(58): Removing non-system package:com.moodswings.moodchart 01-22 17:58:17.655: I/ActivityManager(58): Force stopping package com.moodswings.moodchart uid=10038 01-22 17:58:17.795: D/PackageManager(58): Scanning package com.moodswings.moodchart 01-22 17:58:17.795: I/PackageManager(58): Package com.moodswings.moodchart codePath changed from /data/app/com.moodswings.moodchart-1.apk to /data/app/com.moodswings.moodchart-2.apk; Retaining data and using new 01-22 17:58:17.805: I/PackageManager(58): /data/app/com.moodswings.moodchart-2.apk changed; unpacking 01-22 17:58:17.815: D/installd(34): DexInv: --- BEGIN '/data/app/com.moodswings.moodchart-2.apk' --- 01-22 17:58:18.714: D/dalvikvm(257): DexOpt: load 112ms, verify 486ms, opt 28ms 01-22 17:58:18.784: D/installd(34): DexInv: --- END '/data/app/com.moodswings.moodchart-2.apk' (success) --- 01-22 17:58:18.784: W/PackageManager(58): Code path for pkg : com.moodswings.moodchart changing from /data/app/com.moodswings.moodchart-1.apk to /data/app/com.moodswings.moodchart-2.apk 01-22 17:58:18.794: W/PackageManager(58): Resource path for pkg : com.moodswings.moodchart changing from /data/app/com.moodswings.moodchart-1.apk to /data/app/com.moodswings.moodchart-2.apk 01-22 17:58:18.794: D/PackageManager(58): Activities: com.moodswings.moodchart.MainActivity com.moodswings.saqibchart.MoodSummary 01-22 17:58:18.804: I/ActivityManager(58): Force stopping package com.moodswings.moodchart uid=10038 01-22 17:58:18.924: I/installd(34): move /data/dalvik-cache/[email protected]@[email protected] -> /data/dalvik-cache/[email protected]@[email protected] 01-22 17:58:18.924: D/PackageManager(58): New package installed in /data/app/com.moodswings.moodchart-2.apk 01-22 17:58:19.046: I/ActivityManager(58): Force stopping package com.moodswings.moodchart uid=10038 01-22 17:58:19.205: I/ActivityManager(58): Start proc com.svox.pico for broadcast com.svox.pico/.VoiceDataInstallerReceiver: pid=258 uid=10028 gids={} 01-22 17:58:19.295: W/RecognitionManagerService(58): no available voice recognition services found 01-22 17:58:19.475: I/ActivityThread(258): Publishing provider com.svox.pico.providers.SettingsProvider: com.svox.pico.providers.SettingsProvider 01-22 17:58:19.505: D/dalvikvm(157): GC_EXPLICIT freed 4255 objects / 257880 bytes in 436ms 01-22 17:58:19.625: D/dalvikvm(58): GC_EXPLICIT freed 9153 objects / 569160 bytes in 116ms 01-22 17:58:19.675: I/installd(34): unlink /data/dalvik-cache/[email protected]@[email protected] 01-22 17:58:19.685: D/AndroidRuntime(205): Shutting down VM 01-22 17:58:19.695: D/jdwp(205): adbd disconnected 01-22 17:58:19.714: I/AndroidRuntime(205): NOTE: attach of thread 'Binder Thread #3' failed 01-22 17:58:20.214: D/AndroidRuntime(268): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<< 01-22 17:58:20.214: D/AndroidRuntime(268): CheckJNI is ON 01-22 17:58:20.344: D/AndroidRuntime(268): --- registering native functions --- 01-22 17:58:20.935: I/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.moodswings.moodchart/.MainActivity } 01-22 17:58:21.075: D/AndroidRuntime(268): Shutting down VM 01-22 17:58:21.085: I/ActivityManager(58): Start proc com.moodswings.moodchart for activity com.moodswings.moodchart/.MainActivity: pid=274 uid=10038 gids={} 01-22 17:58:21.094: D/jdwp(268): adbd disconnected 01-22 17:58:21.165: I/dalvikvm(268): JNI: AttachCurrentThread (from ???.???) 01-22 17:58:21.165: I/AndroidRuntime(268): NOTE: attach of thread 'Binder Thread #3' failed 01-22 17:58:21.454: E/jdwp(274): Failed sending reply to debugger: Broken pipe 01-22 17:58:21.454: D/dalvikvm(274): Debugger has detached; object registry had 1 entries 01-22 17:58:21.914: I/ActivityManager(58): Displayed activity com.moodswings.moodchart/.MainActivity: 843 ms (total 20356 ms) 01-22 17:58:21.914: I/ActivityManager(58): Displayed activity com.android.launcher/com.android.launcher2.Launcher: 20358 ms (total 20358 ms) 01-22 17:58:32.785: D/KeyguardViewMediator(58): pokeWakelock(5000) 01-22 17:58:32.995: D/KeyguardViewMediator(58): pokeWakelock(5000) 01-22 17:58:33.354: I/ARMAssembler(58): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x273d28:0x273e34] in 495099 ns 01-22 17:58:33.424: I/ARMAssembler(58): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x29a378:0x29a540] in 676141 ns 01-22 17:58:35.995: D/dalvikvm(106): GC_FOR_MALLOC freed 1450 objects / 218728 bytes in 51ms 01-22 17:58:36.644: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:36.644: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:36.845: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 1992 objects / 136528 bytes in 62ms 01-22 17:58:37.715: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 544 objects / 27840 bytes in 53ms 01-22 17:58:37.944: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:37.944: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:40.515: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 317 objects / 20448 bytes in 94ms 01-22 17:58:40.676: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:40.676: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:43.195: D/dalvikvm(106): GC_EXTERNAL_ALLOC freed 356 objects / 22976 bytes in 74ms 01-22 17:58:43.345: W/KeyCharacterMap(106): No keyboard for id 0 01-22 17:58:43.376: W/KeyCharacterMap(106): Using default keymap: /system/usr/keychars/qwerty.kcm.bin 01-22 17:58:44.665: I/ActivityManager(58): Starting activity: Intent { cmp=com.moodswings.moodchart/.MoodSummary (has extras) } 01-22 17:58:44.665: D/AndroidRuntime(274): Shutting down VM 01-22 17:58:44.665: W/dalvikvm(274): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 01-22 17:58:44.685: E/AndroidRuntime(274): FATAL EXCEPTION: main 01-22 17:58:44.685: E/AndroidRuntime(274): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.moodswings.moodchart/com.moodswings.moodchart.MoodSummary}; have you declared this activity in your AndroidManifest.xml? 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Activity.startActivityForResult(Activity.java:2817) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.Activity.startActivity(Activity.java:2923) 01-22 17:58:44.685: E/AndroidRuntime(274): at com.moodswings.moodchart.MainActivity$1.onClick(MainActivity.java:172) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.view.View.performClick(View.java:2408) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.view.View$PerformClick.run(View.java:8816) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.os.Handler.handleCallback(Handler.java:587) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.os.Handler.dispatchMessage(Handler.java:92) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.os.Looper.loop(Looper.java:123) 01-22 17:58:44.685: E/AndroidRuntime(274): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-22 17:58:44.685: E/AndroidRuntime(274): at java.lang.reflect.Method.invokeNative(Native Method) 01-22 17:58:44.685: E/AndroidRuntime(274): at java.lang.reflect.Method.invoke(Method.java:521) 01-22 17:58:44.685: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-22 17:58:44.685: E/AndroidRuntime(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-22 17:58:44.685: E/AndroidRuntime(274): at dalvik.system.NativeStart.main(Native Method) 01-22 17:58:44.695: W/ActivityManager(58): Force finishing activity com.moodswings.moodchart/.MainActivity 01-22 17:58:45.215: W/ActivityManager(58): Activity pause timeout for HistoryRecord{4a1851c8 com.moodswings.moodchart/.MainActivity} 01-22 17:58:45.314: I/ARMAssembler(58): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x2f9820:0x2f98dc] in 534098 ns 01-22 17:58:48.934: I/Process(274): Sending signal. PID: 274 SIG: 9 01-22 17:58:48.954: I/ActivityManager(58): Process com.moodswings.moodchart (pid 274) has died. 01-22 17:58:48.954: I/WindowManager(58): WIN DEATH: Window{4a2a9f40 com.moodswings.moodchart/com.moodswings.moodchart.MainActivity paused=false} 01-22 17:58:49.036: W/InputManagerService(58): Got RemoteException sending setActive(false) notification to pid 274 uid 10038 01-22 17:58:56.324: W/ActivityManager(58): Activity destroy timeout for HistoryRecord{4a1851c8 com.moodswings.moodchart/.MainActivity} 01-22 17:59:00.075: W/Process(58): Unable to open /proc/274/status

Related

[SOLVED] Cannot Update Market Enabler

So here is my problem. I have been running the latest Cyanogenmod (4.2.14.1) on my HTC Magic 32A, with Market Enabler v3.0 (I think, could be up to v3.2). The other day I tried uninstalling Market Enabler, and upgrading to v3.8. I deleted the existing Market Enabler files manually (/system/sd/app/com.androidiani.MarketEnabler.apk) and the corresponding dalvik-cache file, then rebooted and tried to install Market Enabler v3.8
Now when I try to install Market Enabler (I've tried v3.0, v3.2, and v3.8), I get this error: "MarketEnabler could not be installed on this phone"
I've checked in the applications management screen, and Market Enabler does not show up there. I even reflashed my cyanogenmod ROM and formatted my cache and dalvik-cache, and it still won't work. I have run out of ideas. Any help would be greatly appreciated.
Here is a log of a failed install of Market Enabler:
Code:
02-16 23:47:34.789 I/ActivityManager( 149): Starting activity: Intent { act=android.intent.action.VIEW cat=[android.intent.category.DEFAULT] dat=/sdcard/MarketEnabler_v3.0.8.apk28867.apk cmp=com.android.packageinstaller/.PackageInstallerActivity }
02-16 23:47:34.989 I/ActivityManager( 149): Start proc com.android.packageinstaller for activity com.android.packageinstaller/.PackageInstallerActivity: pid=1644 uid=10014 gids={}
02-16 23:47:35.669 I/PackageParser( 1644): Impliciting adding android.permission.WRITE_EXTERNAL_STORAGE to old pkg com.androidiani.MarketEnabler
02-16 23:47:35.669 I/PackageParser( 1644): Impliciting adding android.permission.READ_PHONE_STATE to old pkg com.androidiani.MarketEnabler
02-16 23:47:35.819 I/installd( 128): free_cache(336612) avail 209719296
02-16 23:47:36.039 I/ActivityManager( 149): Starting activity: Intent { dat=file:///data/data/com.android.packageinstaller/files/MarketEnabler_v3.0.8.apk28867.apk cmp=com.android.packageinstaller/.InstallAppConfirmation (has extras) }
02-16 23:47:36.049 W/InputManagerService( 149): Starting input on non-focused client [email protected] (uid=10014 pid=1644)
02-16 23:47:36.049 W/InputManagerService( 149): Client not active, ignoring focus gain of: [email protected]
02-16 23:47:36.099 I/ActivityManager( 149): Displayed activity com.android.packageinstaller/.PackageInstallerActivity: 1121 ms (total 1121 ms)
02-16 23:47:36.369 D/dalvikvm( 1644): GC freed 1563 objects / 122248 bytes in 136ms
02-16 23:47:36.389 I/PackageParser( 1644): Impliciting adding android.permission.WRITE_EXTERNAL_STORAGE to old pkg com.androidiani.MarketEnabler
02-16 23:47:36.389 I/PackageParser( 1644): Impliciting adding android.permission.READ_PHONE_STATE to old pkg com.androidiani.MarketEnabler
02-16 23:47:36.879 W/InputManagerService( 149): Starting input on non-focused client [email protected] (uid=10198 pid=1518)
02-16 23:47:36.989 I/ActivityManager( 149): Displayed activity com.android.packageinstaller/.InstallAppConfirmation: 881 ms (total 881 ms)
02-16 23:47:38.159 I/InstallAppConfirmation( 1644): result ok
02-16 23:47:38.209 I/ActivityManager( 149): Starting activity: Intent { dat=file:///data/data/com.android.packageinstaller/files/MarketEnabler_v3.0.8.apk28867.apk cmp=com.android.packageinstaller/.InstallAppProgress (has extras) }
02-16 23:47:38.279 W/InputManagerService( 149): Starting input on non-focused client [email protected] (uid=10014 pid=1644)
02-16 23:47:38.829 I/ActivityManager( 149): Displayed activity com.android.packageinstaller/.InstallAppProgress: 586 ms (total 586 ms)
02-16 23:47:39.269 D/PackageParser( 149): Scanning package: /data/app/vmdl74099.tmp
02-16 23:47:39.379 I/PackageParser( 149): Impliciting adding android.permission.WRITE_EXTERNAL_STORAGE to old pkg com.androidiani.MarketEnabler
02-16 23:47:39.379 I/PackageParser( 149): Impliciting adding android.permission.READ_PHONE_STATE to old pkg com.androidiani.MarketEnabler
02-16 23:47:41.079 E/PackageManager( 149): Package com.androidiani.MarketEnabler signatures do not match the previously installed version; ignoring!
02-16 23:47:41.109 W/PackageManager( 149): Package couldn't be installed in /data/app/com.androidiani.MarketEnabler.apk
02-16 23:47:41.709 D/dalvikvm( 149): GC freed 9334 objects / 508664 bytes in 594ms
02-16 23:47:47.559 D/ ( 1644): unable to unlink '/data/data/com.android.packageinstaller/files/MarketEnabler_v3.0.8.apk28867.apk': No such file or directory (errno=2)
02-16 23:47:48.089 I/ActivityManager( 149): Process com.android.packageinstaller (pid 1644) has died.
-=Edit=-
So I ended up running $ adb uninstall com.androidiani.MarketEnabler again, (which previously resulted in "Failure"), but this time it actually worked. Now I can install MarketEnabler again.

[DEV] Modified Skype app with Video

Hi,
I modified the recently leaked skype w/ video app for the HTC Thunderbolt. Let me document my changes and progress so far:
Here is the original app:http://www.droid-life.com/2011/04/11/download-skype-with-video-on-android/
1) if you try to install the app unmodified on a non HTC thunderbolt phone, you will get an "installation failed" message. I decompiled the app using these instructions: http://jack-mannino.blogspot.com/2010/09/reversing-android-apps-101.html
2) I modified the AndroidManifest.xml to remove this line:
<uses-library android:name="com.htc.device" />
3) I then recompiled and resigned the app( http://www.addictivetips.com/mac-os/auto-sign-tool-for-android-developers-on-mac/).
4) The apk now installed on my Nexus S but I get this error when I opened it:
"Sorry, your phone is not able to use this version of Skype. To find out more about Skype on mobile, visit www.skype.com"
5) I looked through the code and found the offending text in com.skype.ui.SplashScreenActivity.class:
protected void onResume()
{
super.onResume();
if (!f.a())
{
Toast.makeText(this, "Sorry, your phone is not able to use this version of Skype. To find out more about Skype on mobile, visit www.skype.com", 1).show();
finish();
}
.....
I commented out the toast and finish() line and then recompiled and resigned.
6) The apk installs but crashes when I try to open it:
W/dalvikvm(17595): VFY: bad arg 1 (into Ljava/lang/CharSequence
W/dalvikvm(17595): VFY: rejecting call to Landroid/widget/Toast;.makeText (Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;
W/dalvikvm(17595): VFY: rejecting opcode 0x71 at 0x0010
W/dalvikvm(17595): VFY: rejected Lcom/skype/merlin_mecha/ui/SplashScreenActivity;.onResume ()V
W/dalvikvm(17595): Verifier rejected class Lcom/skype/merlin_mecha/ui/SplashScreenActivity;
W/dalvikvm(17595): Class init failed in newInstance call (Lcom/skype/merlin_mecha/ui/SplashScreenActivity
D/AndroidRuntime(17595): Shutting down VM
W/dalvikvm(17595): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime(17595): FATAL EXCEPTION: main
E/AndroidRuntime(17595): java.lang.VerifyError: com.skype.merlin_mecha.ui.SplashScreenActivity
E/AndroidRuntime(17595): at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(17595): at java.lang.Class.newInstance(Class.java:1409)
E/AndroidRuntime(17595): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(17595): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1681)
E/AndroidRuntime(17595): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1793)
E/AndroidRuntime(17595): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime(17595): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
E/AndroidRuntime(17595): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(17595): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(17595): at android.app.ActivityThread.main(ActivityThread.java:3848)
E/AndroidRuntime(17595): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(17595): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(17595): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime(17595): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime(17595): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 176): Force finishing activity com.skype.merlin_mecha/.ui.SplashScreenActivity
W/ActivityManager( 176): Force finishing activity info.tikuwarez.launcher3/.ClassicAppPicker
This is my progress so far and here is my modified apk:http://www.mediafire.com/?l6xddlun3u52ung
Does this enable the use of the back camera instead of the front?
For my wife's fascinate
Sent from my ADR6400L using XDA Premium App
@eyeburn : Thanks for the investigation.
Could you try to remove the " if statement " instead ?
I guess the shared library is not only for security, but we will see that later.
More updates. I looked at the SplashScreenActivity.smali code and removed this line:
invoke-virtual {p0}, Lcom/skype/merlin_mecha/ui/SplashScreenActivity;->finish()V
this basically disables the the exiting(the finish() in the code below) of the program during the verizon phone check.
Now the phone doesn't crash but just stays at the "skype mobile" splash screen with the skype background.
I'll look at this again tomorrow. Gonna sleep now.
Updated apk as of midnight Apr 12: http://www.mediafire.com/?eqgr111a7agg3qv
My current thinking is the app is stuck in this while loop:
protected void onResume()
{
super.onResume();
if (!f.a())
{
Toast.makeText(this, "Sorry, your phone is not able to use this version of Skype. To find out more about Skype on mobile, visit www.skype.com", 1).show();
finish();
}
while (true)
{
return;
Intent localIntent1 = new Intent(this, SignInActivity.class);
boolean bool1 = getIntent().getBooleanExtra("LaunchedBySyncAdapter", 0);
Intent localIntent2 = localIntent1.putExtra("LaunchedBySyncAdapter", bool1);
int i = getIntent().getIntExtra("PostLoginCommand", 0);
Intent localIntent3 = localIntent1.putExtra("PostLoginCommand", i);
String str = getIntent().getStringExtra("PostLoginDataUri");
Intent localIntent4 = localIntent1.putExtra("PostLoginDataUri", str);
ac localac = new ac(this, localIntent1);
monitorenter;
try
{
this.a = localac;
Handler localHandler = this.b;
Runnable localRunnable = this.a;
boolean bool2 = localHandler.postDelayed(localRunnable, 1500L);
monitorexit;
continue;
}
finally
{
localObject = finally;
monitorexit;
}
}
throw localObject;
}
}
I keep getting this messages on my logcat:
I/TelephonyRegistry( 176): notifyServiceState: 0 home T - Mobile T - Mobile 310260 UMTS CSS not supported -1 -1RoamInd: -1DefRoamInd: -1EmergOnly: false
I/TelephonyRegistry( 176): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=null interfaceName=rmnet0 networkType=3
I/TelephonyRegistry( 176): notifyServiceState: 0 home T - Mobile T - Mobile 310260 HSDPA CSS not supported -1 -1RoamInd: -1DefRoamInd: -1EmergOnly: false
I/TelephonyRegistry( 176): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=null interfaceName=rmnet0 networkType=8
More likely, that you killed the login intent, which supposed to invoke login activity. You already have 'return' as the first statement of the while loop. The code in it's current state doesn't make sense to me. It should be an exist condition from the loop, otherwise the only way to exit the loop is via exception, which will effectively kill the application.
ivan.volosyuk said:
More likely, that you killed the login intent, which supposed to invoke login activity. You already have 'return' as the first statement of the while loop. The code in it's current state doesn't make sense to me. It should be an exist condition from the loop, otherwise the only way to exit the loop is via exception, which will effectively kill the application.
Click to expand...
Click to collapse
same conclusion here, but I assume this part of code is badly decompiled. There are several other while->true->return in this code.
I/ActivityManager( 176): Starting: Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS dat=package:com.skype.merlin_mecha cmp=com.android.settings/.applications.InstalledAppDetails } from pid 18780
D/dalvikvm(18780): GC_CONCURRENT freed 333K, 48% free 3339K/6343K, external 5923K/6893K, paused 67ms+23ms
I/ActivityManager( 176): Displayed com.android.settings/.applications.InstalledAppDetails: +1s756ms
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
D/szipinf (18780): Initializing inflate state
I/Process ( 176): Sending signal. PID: 18721 SIG: 9
I/ActivityManager( 176): Force stopping package com.skype.merlin_mecha uid=10068
I/ActivityManager( 176): Force finishing activity HistoryRecord{4057dcc8 com.skype.merlin_mecha/.ui.SplashScreenActivity}
W/InputManagerService( 176): Window already focused, ignoring focus gain of: [email protected]
E/InputDispatcher( 176): channel '407ae0c0 com.skype.merlin_mecha/com.skype.merlin_mecha.ui.SplashScreenActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
E/InputDispatcher( 176): channel '407ae0c0 com.skype.merlin_mecha/com.skype.merlin_mecha.ui.SplashScreenActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
I/WindowManager( 176): WIN DEATH: Window{407ae0c0 com.skype.merlin_mecha/com.skype.merlin_mecha.ui.SplashScreenActivity paused=true}
This is what is happening now.
Keep up the good work, a LOT of people will love you if you can get this to work on other phones like the Galaxy S.
Agreed keep up the good work....and Thanks
speaking as someone with a G Tablet, I really want this to work, so please take all the encouragement i can offer!
Keep up the good work.
Oh thank you.
Seriously, I posted about how somebody should modify this to work on all phones yesterday.
As for me, I'm getting "Sorry1, your phone is not able to use this version of skype"
(Wonder why it says "Sorry1")
I'm using a mytouch 4g with cm7 stable
Working on the same thing here on my EVO. I tried your APK but I don't get to the sign-in screen. I removed the same line from the AndroidManifest.xml file that you did so that it would install. I took a different approach and modified the VerizonNetwork and VerizonMerlin check to return 0x1 instead of 0x0 so that it gets by the Toast successfully and I get the sign-in screen. Now after I sign-in, the service crashes.
Code:
I/com.skype.merlin_mecha.service.a(17177): system board:supersonic bootloader:2.10.0001 brand:sprint product:htc_supersonic model:PC36100 manufacturer:HTC device:supersonic display:3.70.651.1 fingerprint:sprint/htc_supersonic/supersonic/supersonic:2.2/FRF91/294884:user/release-keys host:AA109 user:root radio:2.15.00.09.01 tags:release-keys type:user
I/global (17177): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
D/dalvikvm(17177): GC_FOR_MALLOC freed 5340 objects / 712528 bytes in 124ms
I/LSState (12428): EventReceiver:android.intent.action.NOTIFICATION_UPDATE
I/StartSkypeKitOperation(17177): REMOVE THIS ONCE VERIFIED: appToken = KdXVSo6qB9
I/dalvikvm(17177): Jit: resizing JitTable from 4096 to 8192
D/dalvikvm(15756): GC_EXPLICIT freed 3901 objects / 412584 bytes in 100ms
I/ActivityManager(12428): Process com.skype.merlin_mecha (pid 17177) has died.
W/ActivityManager(12428): Scheduling restart of crashed service com.skype.merlin_mecha/.service.SkypeServiceController in 5000ms
{
"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"
}
http://db.tt/umgHYVq
-Daryel
daryel - i tried it and the same happened to me, but there was nothing that said the app force-closed. it simply closed itself and that was that.
it looks like real headway is being made here. I will faithfully watch this until it is finished
oh the sorry1 was a debugging thing hehe.
so it is now crashing in com.skype.merlin_mecha.service.a
Looks to be failing some fingerprint checking. I guess this is where it verifies the phone.
I wonder which file this line is coming from:
I/StartSkypeKitOperation(17177): REMOVE THIS ONCE VERIFIED: appToken = KdXVSo6qB9
New Edit:
Ok the verification is done in com.skype.merlin_mecha.startup.SignInActivity.
I am speculating, the check and crash is in:
protected void onCreate(Bundle paramBundle)
Thanks guys, it looks like you are pretty close to the solution.
Finger crossed
daryelv said:
Working on the same thing here on my EVO. I tried your APK but I don't get to the sign-in screen. I removed the same line from the AndroidManifest.xml file that you did so that it would install. I took a different approach and modified the VerizonNetwork and VerizonMerlin check to return 0x1 instead of 0x0 so that it gets by the Toast successfully and I get the sign-in screen. Now after I sign-in, the service crashes.
Click to expand...
Click to collapse
Sorry but where is this Verizon check?
There are 2 .so missing.
if you look in a/a/a.smali you will find a ref to
/data/data/com.skype.merlin_mecha/lib/libskype_jni.so
And com\skype\a\c.smali has a ref to /data/data/com.test.java_surface/lib/libskype_jni.so
that means there is more to this
eyeburn said:
I wonder which file this line is coming from:
I/StartSkypeKitOperation(17177): REMOVE THIS ONCE VERIFIED: appToken = KdXVSo6qB9
Click to expand...
Click to collapse
Looks like this comes from com\skype\merlin_mecha\service\bs.class
Code:
Object localObject = "M9QA6f6YIH";
if (!com.skype.merlin_mecha.a.b.b)
continue;
if (!com.skype.merlin_mecha.a.b.a)
continue;
localObject = "KdXVSo6qB9";
String str4 = "REMOVE THIS ONCE VERIFIED: appToken = " + (String)localObject;
int k = Log.i("StartSkypeKitOperation", str4);
bo.g(this.c).SetApplicationToken((String)localObject);
boolean bool1 = bo.c(this.c);
if (bool1)
continue;

[Q] What is wrong with my project?

Hi all, I'm fairly new to Java and my overall coding skills are not as advanced as I'd like them to be but I really would appreciate it if someone could help me with this problem.
My first goal is to code an application for Android which measures the acceleration (X, Y, Z directions) and displays the values in a TextView.
There will be other user configurable options like unit conversion or limits with audio warnings etc. later on.
Right now I only have a few lines of code and the application already force closes right after starting.
I am posting my MainActivity.java, my activity_main.xml and the sensoractivity2 Manifest. Please point me in the right direction!
MainActivity.java:
Code:
package com.example.sensoractivity2;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
}
public void onSensorChanged(SensorEvent event) {
float x, y, z = 0;
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
x=event.values[0];
y=event.values[1];
z=event.values[2];
TextView tx = (TextView) findViewById(R.id.textView1);
tx.setText((int) x);
TextView ty = (TextView) findViewById(R.id.textView2);
ty.setText((int) y);
TextView tz = (TextView) findViewById(R.id.textView3);
tz.setText((int) z);
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
}
activity_main.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="X-Wert" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Y-Wert" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Z-Wert" />
</LinearLayout>
sensoractivity2 Manifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sensoractivity2"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity android:name="com.example.sensoractivity2.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
First thing I see is that you are not setting your view in your activity classes "oncreate" method. Can you post your logcat output when the app force closes? That will help the most.
Could you please post a logcat?
Just the lines of your app. Get it using the logcat view in Eclipse.
Look at the bold for changes that will help you. When you are working with view objects, you shouldn't create the object in a listener or something that is called over and over. You will be creating a memory leak.
Code:
package com.example.sensoractivity2;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
[B]TextView tx = null;
TextView ty = null;
TextView tz = null;[/B]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
[B] setContentView(R.layout.activity_main);[/B]
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
[B]tx = (TextView) findViewById(R.id.textView1);
ty = (TextView) findViewById(R.id.textView2);
tz = (TextView) findViewById(R.id.textView3);[/B]
}
public void onSensorChanged(SensorEvent event) {
float x, y, z = 0;
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
x=event.values[0];
y=event.values[1];
z=event.values[2];
[B]tx.setText((int) x);
ty.setText((int) y);
tz.setText((int) z);[/B]
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
}
Here is the part of the catlog which I believe to be relevant when the crash occurs:
Code:
04-28 18:34:24.628: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
04-28 18:34:25.750: E/Trace(1735): error opening trace file: No such file or directory (2)
04-28 18:34:27.452: I/ARMAssembler(36): generated scanline__00000077:03515104_00009002_00000000 [127 ipp] (149 ins) at [0x40f081f0:0x40f08444] in 34521256 ns
04-28 18:34:29.430: I/Choreographer(1153): Skipped 388 frames! The application may be doing too much work on its main thread.
04-28 18:34:29.462: I/ARMAssembler(36): generated scanline__00000077:03010104_00008002_00000000 [ 89 ipp] (110 ins) at [0x40f08450:0x40f08608] in 17654283 ns
04-28 18:34:30.825: W/ActivityManager(1003): Launch timeout has expired, giving up wake lock!
04-28 18:34:31.673: D/AndroidRuntime(1735): Shutting down VM
04-28 18:34:31.673: W/dalvikvm(1735): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-28 18:34:31.737: E/AndroidRuntime(1735): FATAL EXCEPTION: main
04-28 18:34:31.737: E/AndroidRuntime(1735): java.lang.NullPointerException
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:27)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Looper.loop(Looper.java:137)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 18:34:31.737: E/AndroidRuntime(1735): at dalvik.system.NativeStart.main(Native Method)
04-28 18:34:31.813: W/ActivityManager(1003): Force finishing activity com.example.sensoractivity2/.MainActivity
04-28 18:34:31.893: W/WindowManager(1003): Failure taking screenshot for (328x583) to layer 21010
04-28 18:34:32.643: D/dalvikvm(1003): GC_FOR_ALLOC freed 588K, 26% free 7082K/9496K, paused 471ms, total 481ms
Thanks for your hints, zalez! Going to try that now.
The logcat states a nullpointer error. I believe my corrections will fix at least that error.
spelaben said:
Here is the part of the catlog which I believe to be relevant when the crash occurs:
Code:
04-28 18:34:24.628: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property
04-28 18:34:25.750: E/Trace(1735): error opening trace file: No such file or directory (2)
04-28 18:34:27.452: I/ARMAssembler(36): generated scanline__00000077:03515104_00009002_00000000 [127 ipp] (149 ins) at [0x40f081f0:0x40f08444] in 34521256 ns
04-28 18:34:29.430: I/Choreographer(1153): Skipped 388 frames! The application may be doing too much work on its main thread.
04-28 18:34:29.462: I/ARMAssembler(36): generated scanline__00000077:03010104_00008002_00000000 [ 89 ipp] (110 ins) at [0x40f08450:0x40f08608] in 17654283 ns
04-28 18:34:30.825: W/ActivityManager(1003): Launch timeout has expired, giving up wake lock!
04-28 18:34:31.673: D/AndroidRuntime(1735): Shutting down VM
04-28 18:34:31.673: W/dalvikvm(1735): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-28 18:34:31.737: E/AndroidRuntime(1735): FATAL EXCEPTION: main
04-28 18:34:31.737: E/AndroidRuntime(1735): java.lang.NullPointerException
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:27)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.os.Looper.loop(Looper.java:137)
04-28 18:34:31.737: E/AndroidRuntime(1735): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 18:34:31.737: E/AndroidRuntime(1735): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 18:34:31.737: E/AndroidRuntime(1735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 18:34:31.737: E/AndroidRuntime(1735): at dalvik.system.NativeStart.main(Native Method)
04-28 18:34:31.813: W/ActivityManager(1003): Force finishing activity com.example.sensoractivity2/.MainActivity
04-28 18:34:31.893: W/WindowManager(1003): Failure taking screenshot for (328x583) to layer 21010
04-28 18:34:32.643: D/dalvikvm(1003): GC_FOR_ALLOC freed 588K, 26% free 7082K/9496K, paused 471ms, total 481ms
Thanks for your hints, zalez! Going to try that now.
Click to expand...
Click to collapse
zalez said:
The logcat states a nullpointer error. I believe my corrections will fix at least that error.
Click to expand...
Click to collapse
True, nullpointer errors are fixed. After debugging it again, I'm getting these errors now:
Code:
04-28 19:07:59.466: E/AndroidRuntime(858): FATAL EXCEPTION: main
04-28 19:07:59.466: E/AndroidRuntime(858): android.content.res.Resources$NotFoundException: String resource ID #0x0
04-28 19:07:59.466: E/AndroidRuntime(858): at android.content.res.Resources.getText(Resources.java:230)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.widget.TextView.setText(TextView.java:3769)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:33)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Looper.loop(Looper.java:137)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 19:07:59.466: E/AndroidRuntime(858): at dalvik.system.NativeStart.main(Native Method)
Any ideas?
spelaben said:
True, nullpointer errors are fixed. After debugging it again, I'm getting these errors now:
Code:
04-28 19:07:59.466: E/AndroidRuntime(858): FATAL EXCEPTION: main
04-28 19:07:59.466: E/AndroidRuntime(858): android.content.res.Resources$NotFoundException: String resource ID #0x0
04-28 19:07:59.466: E/AndroidRuntime(858): at android.content.res.Resources.getText(Resources.java:230)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.widget.TextView.setText(TextView.java:3769)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.example.sensoractivity2.MainActivity.onSensorChanged(MainActivity.java:33)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.hardware.SystemSensorManager$ListenerDelegate$1.handleMessage(SystemSensorManager.java:204)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.os.Looper.loop(Looper.java:137)
04-28 19:07:59.466: E/AndroidRuntime(858): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invokeNative(Native Method)
04-28 19:07:59.466: E/AndroidRuntime(858): at java.lang.reflect.Method.invoke(Method.java:511)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-28 19:07:59.466: E/AndroidRuntime(858): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-28 19:07:59.466: E/AndroidRuntime(858): at dalvik.system.NativeStart.main(Native Method)
Any ideas?
Click to expand...
Click to collapse
It needs to be
Code:
tx.setText(String.valueOf(x));
ty.setText(String.valueOf(y));
tz.setText(String.valueOf(z));
If you pass an int, the TextView thinks that it is a resource id. That is why you need to convert it to a String first.
I over looked the bold part. When setting text for a Textview, it has to be in string format. There is no implied conversion.
Code:
package com.example.sensoractivity2;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
TextView tx = null;
TextView ty = null;
TextView tz = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager=(SensorManager) getSystemService(SENSOR_SERVICE);
setContentView(R.layout.activity_main);
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
tx = (TextView) findViewById(R.id.textView1);
ty = (TextView) findViewById(R.id.textView2);
tz = (TextView) findViewById(R.id.textView3);
}
public void onSensorChanged(SensorEvent event) {
float x, y, z = 0;
if (event.sensor.getType()==Sensor.TYPE_ACCELEROMETER) {
x=event.values[0];
y=event.values[1];
z=event.values[2];
tx.setText[B](Integer.toString(x)[/B]);
ty.setText([B]Integer.toString(y)[/B]);
tz.setText([B]Integer.toString(z)[/B]);
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
}
nikwen said:
It needs to be
Code:
tx.setText(String.valueOf(x));
ty.setText(String.valueOf(y));
tz.setText(String.valueOf(z));
If you pass an int, the TextView thinks that it is a resource id. That is why you need to convert it to a String first.
Click to expand...
Click to collapse
Yes! That did the trick! Now my next problem is that I only see one value instead of three, from there on I will try to move on by myself.
Sorry, I'm not sure if this is relevant, but you aren't overriding your onCreate method? Could that have anything to do with it?
MaartenXDA said:
Sorry, I'm not sure if this is relevant, but you aren't overriding your onCreate method? Could that have anything to do with it?
Click to expand...
Click to collapse
He does:
public void onCreate(Bundle savedInstanceState) {
Click to expand...
Click to collapse
He just did not wrote the @override annotation before that. As far as i know, you do not have to use it.
EDIT: Yep, it does not matter. See this: http://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why
It says that it is just for ensuring that you are overriding the right method and for making the code easier to read.
Hi all, I am a bit further with my project since I found some time to work on it again.
//edit, force closes on starting fixed!
Here is what it is supposed to be doing: It reads the x, y and z values for acceleration from the LINEAR_ACCELERATION sensor. If a certain value is exceeded a timer will be started. If the amount of seconds the timer counts is higher than a defined threshold, it will play the default notifcation sound.
If the value from the sensor is below the threshold, it will stop the timer. The whole timer thing isn't working, the notification is played as soon as the normal acceleration threshold is passed and the time is ignored.
Please review my code below and tell me what I'm not seeing here, note that I'm still a noob.
Also I'm interested in a method to capture the maximum values read from the sensor and put it in a textview, can you help me?
AccelMeter.java:
Code:
package com.example.accelmeter;
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class AccelMeter extends Activity implements SensorEventListener {
private SensorManager sensorManager;
// Objekte deklarieren
TextView xC;
TextView yC;
TextView zC;
Chronometer chrono;
/* accThreshold = Schwellenwert in m/s² für die Beschleunigung
* accInterval = Zeitraum in Sekunden, über den der Wert für die Beschleunigung überwacht wird
*/
private float accThreshold = 50;
private float accInterval = 0;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accel_meter);
// Achsen Objekte erstellen
xC=(TextView)findViewById(R.id.xCoordinate);
yC=(TextView)findViewById(R.id.yCoordinate);
zC=(TextView)findViewById(R.id.zCoordinate);
/* Sensor.TYPE_LINEAR_ACCELERATION = Beschleunigung auf jeder Achse ohne Gravitation in m/s²
* SENSOR_DELAY_FASTEST = schnellster Modus für Messung. Alternativen z.B. _GAME, _NORMAL oder _UI
*/
sensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
SensorManager.SENSOR_DELAY_NORMAL);
// Schwellenwert festlegen und mit einer Toast-Benachrichtigung bestätigen, Fehlerbehandlung wenn kein Wert eingegeben wurde
Button setThreshold = (Button)findViewById(R.id.setThreshold);
setThreshold.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
EditText et = (EditText)findViewById(R.id.threshold);
accThreshold = Float.valueOf(et.getText().toString());
Toast.makeText(getApplicationContext(), "Neuer Schwellenwert festgelegt!", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Es wurde noch kein Wert eingegeben!", Toast.LENGTH_SHORT).show();
}
}
});
// Intervall festlegen und mit einer Toast-Benachrichtigung bestätigen, Fehlerbehandlung wenn kein Wert eingegeben wurde
Button setInterval = (Button)findViewById(R.id.setInterval);
setInterval.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
EditText et = (EditText)findViewById(R.id.editInterval);
accInterval = Float.valueOf(et.getText().toString());
Toast.makeText(getApplicationContext(), "Neues Intervall festgelegt!", Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "Es wurde noch kein Wert eingegeben!", Toast.LENGTH_SHORT).show();
}
}
});
// Programm beenden
Button exit = (Button)findViewById(R.id.exit);
exit.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
finish();
System.exit(0);
}
});
}
public void onSensorChanged(SensorEvent event){
// Sensor Typ überprüfen
if(event.sensor.getType()==Sensor.TYPE_LINEAR_ACCELERATION){
// Richtungen verknüpfen
float x=event.values[0];
float y=event.values[1];
float z=event.values[2];
// Gerundete Ergebnisse mit vier Nachkommastellen ausgeben
xC.setText("X: "+(Math.abs(Math.round(x * 1000) / 1000.0)));
yC.setText("Y: "+(Math.abs(Math.round(y * 1000) / 1000.0)));
zC.setText("Z: "+(Math.abs(Math.round(z * 1000) / 1000.0)));
// Wenn Beschleunigung über Schwellenwert liegt, starte Timer. Wenn Timer das festgelete Intervall überschreitet, spiele Benachrichtigungston
if (x + y + z > accThreshold)
{
chrono = new Chronometer(this);
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
long seconds = ((chrono.getBase()-SystemClock.elapsedRealtime()/1000%60));
if (seconds >= accInterval)
{
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
}
else
{
chrono.stop();
}
}
}
}
[user=439709]@override[/user]
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
}
activity_accel_meter.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow tools:ignore="ExtraText" >
<TextView
android:id="@+id/xCoordinate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X Koordinate: "
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/yCoordinate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Y Koordinate: "
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
/>
</TableRow>
<TableRow>
<TextView
android:id="@+id/zCoordinate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Z Koordinate: "
android:textAppearance="?android:attr/textAppearanceLarge"
tools:ignore="HardcodedText" />
/>
</TableRow>
<EditText
android:id="@+id/threshold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Schwellenwert (float)"
android:inputType="numberDecimal"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/setThreshold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schwellenwert festlegen"
tools:ignore="HardcodedText" />
<EditText
android:id="@+id/editInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Zeit in Sekunden"
android:inputType="number"
tools:ignore="HardcodedText" >
<requestFocus />
</EditText>
<Button
android:id="@+id/setInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zeitraum für Überwachung festlegen"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beenden"
tools:ignore="HardcodedText" />
</TableLayout>
Yay German code (live there, too) xD Initialise your seconds in your onCreate, it's much nicer and probably the problem. A method gets the highest value the sensor measured would be a simple
Code:
double savedVal=0; //or any other type
private void updateMaxVal(){
double currentVal =// get the value from the specific sensor
if(savedVal<currentVal) {
savedVal = currentVal;
// maybe save the time as well
}
You'd have to put that method in the onsensorchanged so it will be called often. Then update your text View with the new saved value
SimplicityApks said:
Yay German code (live there, too) xD Initialise your seconds in your onCreate, it's much nicer and probably the problem. A method gets the highest value the sensor measured would be a simple
Code:
double savedVal=0; //or any other type
private void updateMaxVal(){
double currentVal =// get the value from the specific sensor
if(savedVal<currentVal) {
savedVal = currentVal;
// maybe save the time as well
}
You'd have to put that method in the onsensorchanged so it will be called often. Then update your text View with the new saved value
Click to expand...
Click to collapse
Hey fellow German!
If I initialise the seconds variable in the onCreate part it says that the variable is not being used (yellow marking) and in the code below I get an error obviously stating that the variable is unknown. ^^
I have three different values, how can I link the x, y and z variables in the method and how can I make sure the variables are known inside of the method? (Same problem as above)
Since I don't know how to do it with a method I just wrote the following code in my onsensorchanged part, the problem is that the max value textviews always show the same as the current value textviews:
float savedValX = 0;
float savedValY = 0;
float savedValZ = 0;
float currentValX = event.values[0];
float currentValY = event.values[1];
float currentValZ = event.values[2];
if (savedValX < currentValX) {
savedValX = currentValX;
xM.setText("X max: "+(Math.abs(Math.round(currentValX * 1000) / 1000.0)));
}
if (savedValY < currentValY) {
savedValY = currentValY;
yM.setText("Y max: "+(Math.abs(Math.round(currentValY * 1000) / 1000.0)));
}
if (savedValZ < currentValZ) {
savedValZ = currentValZ;
zM.setText("Z max: "+(Math.abs(Math.round(currentValZ * 1000) / 1000.0)));
}
Also I still have the problem that my seconds interval is being ignored.
//edit, fixed it! Now I only need the max value method.
OK so I now understand what you are trying to do with your Chronometer, the problem is that you reinitialize it every time the onSensorChanged is called so if you then ask for the seconds it has just started. To fix this, you could set an onChronometerTickListener and set your textViews in that method. To avoid recreating the Chrono use
Code:
if(chrono==null){
chrono = new Chronometer();
chrono.start();
}
If u don't want the tick listener or it doesn't work ( haven't used it yet) you can put your if(seconds<...)in the else {}of above method. But remember that the onSensorChanged is called EVERYTIME the sensor registers a change, this might be very often or just sometimes, so there is no guarantee that the text views will be updated if the else clause in that method is used
PS forget about the initializing of the seconds, I don't know what I was thinking yesterday, but I guess it was too late ...
/*edit:
What I meant with
Code:
double savedVal=0; //or any other type
private void updateMaxVal(){
is that you save your value in your class ("globally"), so that it is accessible to the whole class.
and to do it nicely you can do it like this:
Code:
float savedValX = 0;
float savedValY = 0;
float savedValZ = 0;
boolean change = false;
private void updateMaxVals(SensorEvent event){ // call this method in your onSensorChanged
change = false;
savedValX = getMax(event.values[0], savedValX);
if(change){
xM.setText("X max: "+(Math.abs(Math.round(savedValX * 1000) / 1000.0)));
}
savedValY = getMax(event.values[1], savedValY);
if(change){
yM.setText("Y max: "+(Math.abs(Math.round(savedValY * 1000) / 1000.0)));
}
savedValZ = getMax(event.values[2], savedValZ);
if(change){
yM.setText("Z max: "+(Math.abs(Math.round(savedValZ * 1000) / 1000.0)));
}
}
private float getMax(float currentVal, float savedVal){
if(currentVal > savedVal){
change = true;
return currentVal;
}else{
change = false;
return savedVal;
}
}

[CODE][Q] Pass extra twice(image to mms), or use lastIndexOf() to get file?

Ok so this may get sort of complicated, but I'll try to explain it simply.
I have a mainActivity(viewpager). i take a screenshot of this from ABS options menu. This gets saved to sdcard . WORKS FINE
Code:
this is selecting from the actionbar menu
else if (item.getTitle().toString().equalsIgnoreCase("Take Screengrab")) {
View v1 = R1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
Util.saveBitmap(bm, "folder", "screenshot");
//the above are the folder I chose to name, and the screenshotname{without additional numbering}
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.image4);
//imageview is above. second ativity is below
Intent intent = new Intent(this, Screenshots.class);
intent.putExtra("image", bm);
//"image" is my extra
startActivity(intent);
I send that while its saving, to an ImageView in a second(normal) activity. WORKS FINE
Code:
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screenshots);
//The ImageView where the screenshot goes
ImageView image=(ImageView)findViewById(R.id.image4);
//This "imageId" isnt used, but for some reason the Imageview wont set without it
Intent intent = getIntent();
int imageId = intent.getIntExtra("imageId", -1); // -1 would be a default value//
//this gets my extra
Bitmap bm = (Bitmap)this.getIntent().getParcelableExtra("image");
image.setImageBitmap(bm);
I have a button to share it, it opens with picture attached. SORT OF WORKING
The thing is, I want to automatically pass this same extra Bitmap and attach it to the message.
i can open a message with a known file attached.
Code:
{
Uri smsUri = Uri.parse("tel:0000000");
Intent intent = new Intent(Intent.ACTION_SEND, smsUri);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/folder/screenshot.png"));
intent.putExtra(Intent.EXTRA_TEXT,"Today");
startActivity(intent);
i tried the working in putExtra to the message, but I get a toast from the messaging app "Sorry, cannot attach this image". NO STACK ERRORS. nothign in the logs I can use.
Code:
Uri smsUri = Uri.parse("tel:0000000");
Intent intent = new Intent(Intent.ACTION_SEND, smsUri);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("image"));
intent.putExtra(Intent.EXTRA_TEXT,"Today");
startActivity(intent);
and other stuff like that that.
I currently am loading a known file into the message and it works perfect. Problem is, I wont know the name of the file, because my screenshots get saved as image1, image2, etc. So it will be different in every case.
So im wondering if its even possible to pass and extra through twice like that, or if I should look into return the latest image in that sdcard folder with like lastIndexOf(), or something similar.
basically, is there a way to simply query find and attach the highest numbered file? without a GUI(i can do select from gallery, but am trying to make it more automated).
any thoughts would be appreciated.
P.S. i know about the lint errors and things, and somewhat sloppy self taught java, but its working. only worried about the image passing.
out of ideas said:
Ok so this may get sort of complicated, but I'll try to explain it simply.
I have a mainActivity(viewpager). i take a screenshot of this from ABS options menu. This gets saved to sdcard . WORKS FINE
Code:
this is selecting from the actionbar menu
else if (item.getTitle().toString().equalsIgnoreCase("Take Screengrab")) {
View v1 = R1.getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap bm = v1.getDrawingCache();
Util.saveBitmap(bm, "folder", "screenshot");
//the above are the folder I chose to name, and the screenshotname{without additional numbering}
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.image4);
//imageview is above. second ativity is below
Intent intent = new Intent(this, Screenshots.class);
intent.putExtra("image", bm);
//"image" is my extra
startActivity(intent);
I send that while its saving, to an ImageView in a second(normal) activity. WORKS FINE
Code:
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screenshots);
//The ImageView where the screenshot goes
ImageView image=(ImageView)findViewById(R.id.image4);
//This "imageId" isnt used, but for some reason the Imageview wont set without it
Intent intent = getIntent();
int imageId = intent.getIntExtra("imageId", -1); // -1 would be a default value//
//this gets my extra
Bitmap bm = (Bitmap)this.getIntent().getParcelableExtra("image");
image.setImageBitmap(bm);
I have a button to share it, it opens with picture attached. SORT OF WORKING
The thing is, I want to automatically pass this same extra Bitmap and attach it to the message.
i can open a message with a known file attached.
Code:
{
Uri smsUri = Uri.parse("tel:0000000");
Intent intent = new Intent(Intent.ACTION_SEND, smsUri);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/folder/screenshot.png"));
intent.putExtra(Intent.EXTRA_TEXT,"Today");
startActivity(intent);
i tried the working in putExtra to the message, but I get a toast from the messaging app "Sorry, cannot attach this image". NO STACK ERRORS. nothign in the logs I can use.
Code:
Uri smsUri = Uri.parse("tel:0000000");
Intent intent = new Intent(Intent.ACTION_SEND, smsUri);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("image"));
intent.putExtra(Intent.EXTRA_TEXT,"Today");
startActivity(intent);
and other stuff like that that.
I currently am loading a known file into the message and it works perfect. Problem is, I wont know the name of the file, because my screenshots get saved as image1, image2, etc. So it will be different in every case.
So im wondering if its even possible to pass and extra through twice like that, or if I should look into return the latest image in that sdcard folder with like lastIndexOf(), or something similar.
basically, is there a way to simply query find and attach the highest numbered file? without a GUI(i can do select from gallery, but am trying to make it more automated).
any thoughts would be appreciated.
P.S. i know about the lint errors and things, and somewhat sloppy self taught java, but its working. only worried about the image passing.
Click to expand...
Click to collapse
I would just pass the filename to the share intent. In your saving method return the file name and pass it to the Uri.
lastIndexOf is a bad idea. What will you do if somebody saves a file called "xyz" in the same directory? The app will send this every time. So store the filename and pass it to the Uri.
nikwen said:
I would just pass the filename to the share intent. In your saving method return the file name and pass it to the Uri.
lastIndexOf is a bad idea. What will you do if somebody saves a file called "xyz" in the same directory? The app will send this every time. So store the filename and pass it to the Uri.
Click to expand...
Click to collapse
Yeah I had originally tried going about it that, with like getFileStreamPath and things like that, tried about a dozen different things but couldnt get them working. best i can get is that "sorry cant add..." message from the messaging app, which tells me that its passing the image, but it cant attach for some unknown reason(too large doesn't seem right, cuz i can do it with the known file name).
im a dum dum a probably should put this util class
Code:
static String saveBitmap(Bitmap bitmap, String dir, String baseName) {
try {
File sdcard = Environment.getExternalStorageDirectory();
File pictureDir = new File(sdcard, dir);
pictureDir.mkdirs();
File f = null;
for (int i = 1; i < 200; ++i) {
String name = baseName + i + ".png";
f = new File(pictureDir, name);
if (!f.exists()) {
break;
}
}
if (!f.exists()) {
String name = f.getAbsolutePath();
FileOutputStream fos = new FileOutputStream(name);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
//how to get "name" in third activity
return name;
}
} catch (Exception e) {
} finally {
/*
if (fos != null) {
fos.close();
}
*/
}
return null;
}
So I have the name there, but just cant get it over to the messaging. I'm wondering if I should take the pic and automaticaaly pin it to the MMS, and skip the imageview part?
First: Please get a logcat.
Second: This should be working if you use the right path:
Code:
Uri smsUri = Uri.parse("tel:0000000");
Intent intent = new Intent(Intent.ACTION_SEND, smsUri);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("<path here>"));
intent.putExtra(Intent.EXTRA_TEXT,"Today");
startActivity(intent);
(got it from your first post)
1. This is a for instance situtation of if i try sliding the extra or something else into Uri.parse()
E/Mms/compose( 1063): DRM error in onActivityResult()!
E/Mms/media( 1063): IOException caught while opening or reading stream
E/Mms/media( 1063): java.io.FileNotFoundException: No content provider: image
But the content of image makes it into the ImageView(as "getParcelableExtra("image"), just not in the MMS, so I don't know.
2. Yeah it works Perfect when I hardcode in a file( sdcard/folder/image1.png). attaches and sends perfect.
The problem is basically I have a loose understanding of how I should be doing this, and just cant figure out how I should properly be getting it to load.
Banging my head against the wall on this one. lol. :fingers-crossed:
out of ideas said:
1. This is a for instance situtation of if i try sliding the extra or something else into Uri.parse()
E/Mms/compose( 1063): DRM error in onActivityResult()!
E/Mms/media( 1063): IOException caught while opening or reading stream
E/Mms/media( 1063): java.io.FileNotFoundException: No content provider: image
But the content of image makes it into the ImageView(as "getParcelableExtra("image"), just not in the MMS, so I don't know.
2. Yeah it works Perfect when I hardcode in a file( sdcard/folder/image1.png). attaches and sends perfect.
The problem is basically I have a loose understanding of how I should be doing this, and just cant figure out how I should properly be getting it to load.
Banging my head against the wall on this one. lol. :fingers-crossed:
Click to expand...
Click to collapse
The problem is that you do not pass the right file name. So it cannot find the file.
---------- Post added at 07:55 PM ---------- Previous post was at 07:48 PM ----------
Change it to this and tell us the log output:
Code:
static String saveBitmap(Bitmap bitmap, String dir, String baseName) {
try {
File sdcard = Environment.getExternalStorageDirectory();
File pictureDir = new File(sdcard, dir);
pictureDir.mkdirs();
File f = null;
for (int i = 1; i < 200; ++i) {
String name = baseName + i + ".png";
f = new File(pictureDir, name);
if (!f.exists()) {
break;
}
}
if (!f.exists()) {
Log.d("file", "file does not exist");
String name = f.getAbsolutePath();
FileOutputStream fos = new FileOutputStream(name);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
//how to get "name" in third activity
if (name != null) {
Log.d("return", name);
} else {
Log.d("return", "name = null");
}
return name;
} else {
Log.d("file", "file exists");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
/*
if (fos != null) {
fos.close();
}
*/
}
Log.d("return", "null");
return null;
}
I just inserted some debugging things. Check the logcat (and post it).
Did you add this to your manifest?
Code:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
nikwen said:
The problem is that you do not pass the right file name. So it cannot find the file.
I just inserted some debugging things. Check the logcat (and post it).
Did you add this to your manifest?
Code:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Click to expand...
Click to collapse
i know! I just need a way to get what my Util class returns as name. then open that attached to Message. It seems like it should be a lot easier than I am making it.
i added your logs, but the only match back I get is here (I put in some extra stuff)
Code:
D/ViewRoot( 2072): Dispatching pointer MotionEvent{2b00f540 action=1 x=85.33334 y=179.98325 pressure=0.20000002 size=0.20000002} to [email protected]
D/dalvikvm( 2072): GC_EXTERNAL_ALLOC freed 82K, 45% free 3083K/5575K, external 2159K/2284K, paused 57ms
//[B]THIS RIGHT BELOW HERE IS THE FILENAME. I NEED TO RETURN IT IN THE OTHER ACTIVITY. But How?
D/return ( 2072): /mnt/sdcard/folder/screen162.png
[/B]
I/ActivityManager( 182): Starting: Intent { cmp=com.myapp/.Screenshots (has extras) } from pid 2072
E/ActivityThread( 2072): >>> handling: 101
W/WindowManager( 182): Reached focused app: AppWindowToken{2b70bbf8 token=HistoryRecord{2b28ff08 com.myapp/.Screenshots}}
W/WindowManager( 182): updateFocusedWindowLocked newFocus=null mode=0 mCurrentFocus = Window{2b332630 PopupWindow:2afbd178 paused=false}
W/WindowManager( 182): Reached focused app: AppWindowToken{2b70bbf8 token=HistoryRecord{2b28ff08 com.myapp/.Screenshots}}
W/WindowManager( 182): updateFocusedWindowLocked newFocus=Window{2b408a60 com.myapp/com.myapp.Screenshots paused=false} mode=2 mCurrentFocus = Window{2b408a60 com.myapp/com.myapp.Screenshots paused=false}
W/WindowManager( 182): updateFocusedWindowLocked newFocus=Window{2b408a60 com.myapp/com.myapp.Screenshots paused=false} mode=3 mCurrentFocus = Window{2b408a60 com.myapp/com.myapp.Screenshots paused=false}
W/WindowManager( 182): Window Window{2b320c38 com.myapp/com.myapp.MainActivity paused=false} destroying surface Surface(name=com.myapp/com.myapp.MainActivity, identity=204), session Session{2b542460 uid 10050}
W/WindowManager( 182): Window Window{2b332630 PopupWindow:2afbd178 paused=false} destroying surface Surface(name=PopupWindow:2afbd178, identity=205), session Session{2b542460 uid 10050}
I/ActivityManager( 182): Displayed com.myapp/.Screenshots: +549ms
W/WindowManager( 182): Reached focused app: AppWindowToken{2b2dfeb8 token=HistoryRecord{2b395530 com.android.mms/.ui.ComposeMessageActivity}}
D/ActivityThread( 2072): <<< done: 106
W/WindowManager( 182): updateFocusedWindowLocked newFocus=null mode=3 mCurrentFocus = null
W/WindowManager( 182): Reached focused app: AppWindowToken{2b2dfeb8 token=HistoryRecord{2b395530 com.android.mms/.ui.ComposeMessageActivity}}
W/WindowManager( 182): Reached focused app: AppWindowToken{2b2dfeb8 token=HistoryRecord{2b395530 com.android.mms/.ui.ComposeMessageActivity}}
W/WindowManager( 182): Reached focused app: AppWindowToken{2b2dfeb8 token=HistoryRecord{2b395530 com.android.mms/.ui.ComposeMessageActivity}}
W/WindowManager( 182): updateFocusedWindowLocked newFocus=null mode=3 mCurrentFocus = null
W/WindowManager( 182): Reached focused app: AppWindowToken{2b2dfeb8 token=HistoryRecord{2b395530 com.android.mms/.ui.ComposeMessageActivity}}
W/WindowManager( 182): updateFocusedWindowLocked newFocus=null mode=3 mCurrentFocus = null
I/ActivityThread( 2081): Pub com.android.mms.SuggestionsProvider:
com.android.mms.SuggestionsProvider
E/MmsCustom( 2081): Mms,MmsCustom
E/MmsCustom( 2081): Init before calling function of doPreSotred()
E/MmsCustom( 2081): mms config have been prestored before
Yeah, I took 162 screenshots so far trying to get this. lol.
And yeah I declared the right permissions and everything. It takes the screenshot, saves it, and passes it to an ImageView in a different activity perfectly.
I can open Messaging, or FB,picassa, etc. It appends the text, but no image. BUT, i can simply hit attach from the opened message, and add in whatever picture I want.
I thought about just sending people into the gallery to pick, but the android numbering convention doesn't load images in sequential order, but a sort of numerical alphabetical( it saves likes 1, 10, 11,12,13,14,15,16,17,18,19,2,20,21,22,etc). At least this is with quickpic.
So they really get jumbled up, especially with 100+ in there(1, 10,100,11,12). And the point of this segment of the app is to share the most recent image.
i also dont want to just use the currentsystem time, because a ton of numbers is too confusing if they want to find a different one.
Thanks a lot for the help.
Let's try:
Code:
[COLOR="Red"]String path = Utils.saveBitmap(bitmap, dir, baseName);[/COLOR] //replace Utils by your class name
Uri smsUri = Uri.parse("tel:0000000");
Intent intent = new Intent(Intent.ACTION_SEND, smsUri);
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_STREAM, Uri.[COLOR="Red"]fromFile(path)[/COLOR]);
intent.putExtra(Intent.EXTRA_TEXT,"Today");
[COLOR="Red"]intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);[/COLOR]
startActivity(intent);
Took awhile to get Eclipse to accept it, but now I get
Code:
W/System.err( 2002): java.lang.NullPointerException
W/System.err( 2002): at com.MYAPP.Util.saveBitmap(Util.java:39)
//////The top red line you suggested
W/System.err( 2002): at com.MYAPP.Screenshots.onOptionsItemSelected(Screenshots.java:79)
W/System.err( 2002): at android.support.v4.app.Watson.onMenuItemSelected(Watson.java:119)
W/System.err( 2002): at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:603)
W/System.err( 2002): at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:529)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:83)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:158)
W/System.err( 2002): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
W/System.err( 2002): at android.widget.ListView.performItemClick(ListView.java:3513)
W/System.err( 2002): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
W/System.err( 2002): at android.os.Handler.handleCallback(Handler.java:587)
W/System.err( 2002): at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err( 2002): at android.os.Looper.loop(Looper.java:130)
W/System.err( 2002): at android.app.ActivityThread.main(ActivityThread.java:3822)
W/System.err( 2002): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 2002): at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err( 2002): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
W/System.err( 2002): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
W/System.err( 2002): at dalvik.system.NativeStart.main(Native Method)
D/return ( 2002): null
D/AndroidRuntime( 2002): Shutting down VM
W/dalvikvm( 2002): threadid=1: thread exiting with uncaught exception (group=0x2aac4560)
E/AndroidRuntime( 2002): FATAL EXCEPTION: main
E/AndroidRuntime( 2002): java.lang.NullPointerException: uriString
E/AndroidRuntime( 2002): at android.net.Uri$StringUri.<init>(Uri.java:420)
E/AndroidRuntime( 2002): at android.net.Uri$StringUri.<init>(Uri.java:410)
E/AndroidRuntime( 2002): at android.net.Uri.parse(Uri.java:382)
//////The Changed Uri.getFile(); Line
E/AndroidRuntime( 2002): at com.MYAPP.Screenshots.onOptionsItemSelected(Screenshots.java:82)
E/AndroidRuntime( 2002): at android.support.v4.app.Watson.onMenuItemSelected(Watson.java:119)
E/AndroidRuntime( 2002): at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:603)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:529)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:83)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:158)
E/AndroidRuntime( 2002): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime( 2002): at android.widget.ListView.performItemClick(ListView.java:3513)
E/AndroidRuntime( 2002): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
E/AndroidRuntime( 2002): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 2002): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2002): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 2002): at android.app.ActivityThread.main(ActivityThread.java:3822)
E/AndroidRuntime( 2002): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2002): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 2002): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 2002): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 2002): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 181): Force finishing activity com.MYAPP/.Screenshots
W/WindowManager( 181)
Starting to think I should just dump the whole imageview thing.
i need to figure out if i can save to SD how I am doing, and ALSO save to a cache (and overwrite other ones, so only one image persists there)
out of ideas said:
Took awhile to get Eclipse to accept it, but now I get
Code:
W/System.err( 2002): java.lang.NullPointerException
W/System.err( 2002): at com.MYAPP.Util.saveBitmap(Util.java:39)
//////The top red line you suggested
W/System.err( 2002): at com.MYAPP.Screenshots.onOptionsItemSelected(Screenshots.java:79)
W/System.err( 2002): at android.support.v4.app.Watson.onMenuItemSelected(Watson.java:119)
W/System.err( 2002): at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:603)
W/System.err( 2002): at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:529)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:83)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
W/System.err( 2002): at com.actionbarsherlock.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:158)
W/System.err( 2002): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
W/System.err( 2002): at android.widget.ListView.performItemClick(ListView.java:3513)
W/System.err( 2002): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
W/System.err( 2002): at android.os.Handler.handleCallback(Handler.java:587)
W/System.err( 2002): at android.os.Handler.dispatchMessage(Handler.java:92)
W/System.err( 2002): at android.os.Looper.loop(Looper.java:130)
W/System.err( 2002): at android.app.ActivityThread.main(ActivityThread.java:3822)
W/System.err( 2002): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err( 2002): at java.lang.reflect.Method.invoke(Method.java:507)
W/System.err( 2002): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
W/System.err( 2002): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
W/System.err( 2002): at dalvik.system.NativeStart.main(Native Method)
D/return ( 2002): null
D/AndroidRuntime( 2002): Shutting down VM
W/dalvikvm( 2002): threadid=1: thread exiting with uncaught exception (group=0x2aac4560)
E/AndroidRuntime( 2002): FATAL EXCEPTION: main
E/AndroidRuntime( 2002): java.lang.NullPointerException: uriString
E/AndroidRuntime( 2002): at android.net.Uri$StringUri.<init>(Uri.java:420)
E/AndroidRuntime( 2002): at android.net.Uri$StringUri.<init>(Uri.java:410)
E/AndroidRuntime( 2002): at android.net.Uri.parse(Uri.java:382)
//////The Changed Uri.getFile(); Line
E/AndroidRuntime( 2002): at com.MYAPP.Screenshots.onOptionsItemSelected(Screenshots.java:82)
E/AndroidRuntime( 2002): at android.support.v4.app.Watson.onMenuItemSelected(Watson.java:119)
E/AndroidRuntime( 2002): at com.actionbarsherlock.ActionBarSherlock.callbackOptionsItemSelected(ActionBarSherlock.java:603)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.ActionBarSherlockCompat.onMenuItemSelected(ActionBarSherlockCompat.java:529)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:738)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:83)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:148)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:879)
E/AndroidRuntime( 2002): at com.actionbarsherlock.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:158)
E/AndroidRuntime( 2002): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
E/AndroidRuntime( 2002): at android.widget.ListView.performItemClick(ListView.java:3513)
E/AndroidRuntime( 2002): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
E/AndroidRuntime( 2002): at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 2002): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2002): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 2002): at android.app.ActivityThread.main(ActivityThread.java:3822)
E/AndroidRuntime( 2002): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2002): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 2002): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 2002): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 2002): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 181): Force finishing activity com.MYAPP/.Screenshots
W/WindowManager( 181)
Starting to think I should just dump the whole imageview thing.
i need to figure out if i can save to SD how I am doing, and ALSO save to a cache (and overwrite other ones, so only one image persists there)
Click to expand...
Click to collapse
Post your code. We cannot help you if you just say "I changed this line."
It is not getFile but fromFile.
HaHa I know, im not trying to throw puzzles out at people randomly.
But the errors in the log were from those new lines(in red)
the string path
and fromFile path ones
I may be getting somewhere with this though, i found a little section on stackoverflow that i hadn't seen in the other 30 questions about images or screenshots. :fingers-crossed:
Plus i glad I always have about 5 other projects on can work on when I get stuck.
out of ideas said:
HaHa I know, im not trying to throw puzzles out at people randomly.
But the errors in the log were from those new lines(in red)
the string path
and fromFile path ones
I may be getting somewhere with this though, i found a little section on stackoverflow that i hadn't seen in the other 30 questions about images or screenshots. :fingers-crossed:
Plus i glad I always have about 5 other projects on can work on when I get stuck.
Click to expand...
Click to collapse
The problem occurs in the saveBitmap method. For that reason the path is null and then a NPE is thrown. Check your code to save the bitmap.

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

Categories

Resources