Android vibrator app force close - android

my app force closes I do not know why. All it should do is vibrating when it is in the foreground and stop if it is not but when I start it on my phone it force closes. I added lines about vibrator usage into the manifest by hand. Maybe this is the problem. I have to anything else with it to be valid for the app?
My manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.kevinboonemidi"
android:versionCode="1"
android:versionName="1.0" >
<permission android:name="android.permission.VIBRATE" ></permission>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.haptic.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My code:
package com.example.haptic_sof;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.example.kevinboonemidi.R;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
public class MainActivity extends Activity
{
protected Vibrator v = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
long pwmCycles[];
pwmCycles = new long[4];
v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = { 0, 200, 10 };
v.vibrate(pattern, 0);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
protected void onPause(){
super.onPause();
v.cancel();
}
protected void onStop()
{
super.onStop();
v.cancel();
}
}

Your packages are a mess.
You define com.example.kevinboonemidi as your package in the manifest, declare your Activity to be in com.example.haptic and actually put your Activity in com.example.haptic_sof.
Change android:name="com.example.haptic.MainActivity" to android:name="com.example.haptic_sof.MainActivity" and your app should run, though you may need to end up using one package entirely at least to start with.

Related

"Error: cannot find symbol class app"

I have external package class (my custom library), which I want to include in the project. It uses Activity, but shows error as you see.
If I place this command in main project class, it works well... What to do?
Here is the code:
package com.__MyDefaultLibrary;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.ScaleAnimation;
import android.widget.*;
import java.io.File;
import java.util.Calendar;
//
import android.app.Activity;
import com.oceanesa.samplevideorecorder.R;
public class __MyDefaultFunctions{
public android.app.Activity actv1 = android.app.Activity;
public void Initt(){
PreferenceManager.setDefaultValues(actv1.getBaseContext(), R.xml.mypreferences, false);
}
// ========== MY CUSTOM LIBRARY =============//
//button find
public Button fvb(int id) {
return (Button) actv1.findViewById(id);
}
//message show
public void msg(String text) {
Toast.makeText(actv1.getApplicationContext(), text, Toast.LENGTH_LONG).show();
}
public View.OnClickListener optionsListener2 = new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(actv1.getBaseContext(), com.__MyDefaultLibrary.__MyDefaultPreferencesInit1.class);
actv1.startActivity(i);
}
};
}
And AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.oceanesa.samplevideorecorder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#style/AppTheme"
>
<activity
android:name="com.oceanesa.samplevideorecorder.VideoCaptureExample"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.__MyDefaultLibrary.__MyDefaultPreferencesInit1"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Update Answer just passing context to class
public class MyClass {
private static Context mContext;
private static Activity mActivity;
public MyClass(Context c) {
mContext= c;
}
public MyClass(Activity act) {
mActivity= act;
}
public static void showToastMethod() {
// then passing context or activity to
Toast.makeText(mContext, "mymessage ", Toast.LENGTH_SHORT).show();
// or Toast.makeText(mActivity, "mymessage ", Toast.LENGTH_SHORT).show();
}
}
Finally I got it working with the help of topic: How to display a Toast message in from a class that doesn't extend Activity
Problem was in my code. There was no need to call andorid.app at all. I didnt pass Activity to my external file, from where I couldnt call anything..
I had to pass activity like this (from main project file):
public MyExternalClass myEx = new MyExternalClass(Activity);
and needed some modifications...

Android AccountManager.addAccountExplicitly is stopping my App

I'm still having problems with the Method AccountManager.addAccountExplicitly.
I want to create a App which is submitting a User PW combo to a website.
The app should save the login data and therefore i wanted to use AccountManager:
HttpAuth.java:
package com.geberit.eismi.httpauth;
import android.os.Bundle;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.HttpAuthHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.Button;
public class HttpAuth extends Activity {
private EditText field_username;
private EditText field_password;
private Button btn_login;
private AccountManager accountM;
private Account eismi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
accountM = AccountManager.get(this);
eismi = new Account("eismi", "com.geberit.sap.t81");
boolean test = accountM.addAccountExplicitly(eismi, "testpassword", null);
field_username = (EditText) findViewById(R.id.field_user);
field_password = (EditText) findViewById(R.id.field_password);
btn_login = (Button) findViewById(R.id.btn_login);
field_username.setText(accountM.getPassword(eismi));
HttpAuth Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geberit.eismi.httpauth"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="com.geberit.eismi"
>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.geberit.eismi.httpauth.HttpAuth"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Everytime when executing the step
boolean test = accountM.addAccountExplicitly(eismi, "testpassword", null);
my app is stopping!!
some output of the console:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.geberit.eismi.httpauth/com.geberit.eismi.httpauth.HttpAuth}: java.lang.SecurityException: caller uid 10039 is different than the authenticator's uid
I hope you can help me
Thanks Michi

to get cdma dbm on android device

I had tried this one to show my evdo dbm.
it could run on my emulator but couldnt on my real device, why?
is there somethinh wrong ?
this my source code :
package com.cdbmsof2;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class CdBmSOF2MainActivity extends Activity implements OnClickListener {
TextView dateAndTimeLabel;
private Button closeButton;
private int signalDBM = 0;
public class GetParams extends PhoneStateListener
{
#Override
public void onSignalStrengthsChanged(SignalStrength signalStrength)
{
super.onSignalStrengthsChanged(signalStrength);
signalDBM = signalStrength.getEvdoDbm();
}
}
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_cd_bm_sof2_main);
GetParams listener = new GetParams();
TelephonyManager TelManager = ( TelephonyManager )getSystemService(Context.TELEPHONY_SERVICE);
TelManager.listen(listener ,PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
Button btn=(Button)findViewById(R.id.start);
btn.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.start:
Toast.makeText(this, "CDMA signal strength is " + this.signalDBM , Toast.LENGTH_SHORT).show();
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_cd_bm_sof2_main, menu);
return true;
}
}
this my manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cdbmsof2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".CdBmSOF2MainActivity"
android:label="#string/title_activity_cd_bm_sof2_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
</manifest>
any one would help me please? best regards.
You may want to change the MODIFY permission into a READ permission as you're not modifying phone state, but trying to read it:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I tried your code but the value of the signalDBM will not change. It will stay the same even if there is no internet connection at all. I am trying to do something similar and your code was of good help for me but now I face that problem. Does that program changes the values for you? Please let me know..

Program force close

Here is my PlayerActivity:
package player.org;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.app.Activity;
import android.os.Bundle;
public class PlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaView media=new MediaView(this);
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(media);
}
}
here is my MediaView:
package player.org;
import android.app.Activity;
import android.view.*;
import android.widget.ImageView;
import android.content.*;
import android.content.*;
import android.graphics.Color;
class MediaView extends View
{
public MediaView(Context context)
{
super(context);
setBackgroundColor(Color.WHITE);
}
}
and here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="player.org"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity
android:name=".MediaView"
android:label="#string/MediaView_title">
</activity>
<activity android:name=".PlayerActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
But when I Launch the app., It force closes.
Do you have any suggestions?
Thanks for your answers
You are writing this line private MediaView media=new MediaView(this);,before the Activity is initiated.So 'this' keyword is force closing your application
Please use like this
public class PlayerActivity extends Activity {
/** Called when the activity is first created. */
private MediaView media;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(media);
media=new MediaView(this);
}
}

Android project problem

here
I uploaded my Android project made in Eclipse. The idea is that i have a service, which computes the sum of two random numbers. But when i press the OK Button, i don't see the result in that edit box... why? What i'm doing wrong? Please help
Thanks!
EDIT: The code:
//service class
package service;
import java.util.Random;
import com.android.AplicatieSuma;
import android.widget.EditText;
import android.widget.TextView;
public class ServiciuSuma
{
public ServiciuSuma() { }
public int CalculateSum()
{
Random generator=new Random();
int n=generator.nextInt();
int m=generator.nextInt();
return n+m;
}
}
The Application class:
package com.android;
import android.app.*;
import service.*;
public class ApplicationSum extends Application {
public ServiciuSuma service = new ServiciuSuma();
}
and the main Activity class:
package com.android;
import com.android.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class Activitate extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View btn_ok = findViewById(R.id.btn_ok);
btn_ok.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
CalculeazaSuma();
}
});
}
private void CalculeazaSuma()
{
AplicatieSuma appState = ((AplicatieSuma)this.getApplication());
EditText txt_amount = (EditText)findViewById(R.id.txt_amount);
txt_amount.setText(appState.service.CalculateSum());
//BindData();
}
}
So that edit text does not show the sum of the random generated numbers, by the service. What's wrong?
Thanks
EDIT:
the manifest xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android"
android:versionCode="1"
android:versionName="1.0.1">
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true" />
<application android:name="ApplicationSum" android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
<activity android:label="#string/app_name" android:name=".Activitate">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />
</manifest>
This fix will work:
txt_amount.setText(String.valueOf(appState.service.CalculateSum()));
Without that you pass integer and android thinks it's an id of a resource to display. You should really use DDMS to identify such problems.
Have you specified in manifest that you want ApplicationSum to be used as application class?
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:name="com.android.ApplicationSum">
...
</application>
</manifest>
Does this work?
public String CalculateSum()
{
Random generator=new Random();
int n=generator.nextInt();
int m=generator.nextInt();
String sum = Integer.toString(n+m) ;
Log.v("CalculateSum", "N+M = " + sum);
return sum;
}

Categories

Resources