Button not doing anything when it should - java

MainActivity.java
package com.example.mdpmk1;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Context;
import android.net.wifi.ScanResult;
import android.widget.Button;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
public class MainActivity extends Activity {
Button bt, bt2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt = (Button) findViewById(R.id.scan);
bt2 = (Button) findViewById(R.id.getResults);
bt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// do initiatescan
}
});
bt2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(MainActivity.this, ScanResult.class);
startActivity(intent);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
//super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
} else if (resultCode == RESULT_CANCELED) {
}
}
}
#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;
}
}
IntentIntegrator.java
Can be found HERE
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/appName"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/scanClick" />
<Button
android:id="#+id/getResults"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/getResults" />
</LinearLayout>
Mainfest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mdpmk1"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:debuggable="true"
android:name="com.example.mdpmk1.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>
<activity android:name=".ScanScreen" />
<activity android:name=".ScanResults" />
</application>
</manifest>
This is in response to Aniruddha who requested this code to help me with question asked HERE If anyone else could tell me why my button 2 doesnt work that would be lovely thanks.

What you have
<activity android:name=".ScanResults" />
And when using intent
Intent intent = new Intent(MainActivity.this, ScanResult.class);
ScanResults and ScanResult are not the same.
If Activity is not found you should get ActivityNotFoundException.
This exception is thrown when a call to startActivity(Intent) or one
of its variants fails because an Activity can not be found to execute
the given Intent.
http://developer.android.com/reference/android/content/ActivityNotFoundException.html

Related

Turn phoneSpeakers when start a call

I trying to turn on the Speaker after starting a call with a Button. But the Speaker don't get turn on. My Code:
I tried audioManager.setMode(AudioManager.MODE_IN_CALL); but it dont worked.
What I'm doing wrong?
MainActivity.java
package app.fabi.telefon_freisprech;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
AudioManager audioManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonCall);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
check();
Intent myIntent = new Intent(Intent.ACTION_CALL);
String phNum = "tel:" + "+123456789";
myIntent.setData(Uri.parse(phNum));
startActivity( myIntent ) ;
audioManager = (AudioManager)getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
}
});
}
void check(){
if (ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
// first check for permissions
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.CALL_PHONE,
Manifest.permission.CALL_PHONE, Manifest.permission.CALL_PHONE}
, 10);
}
return;
}
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/buttonCall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anrufen +123456789" />
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="app.fabi.telefon_freisprech">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I think its not a big thing but i don't get it to work.

I cannot get Google Maps API to work on my android Application (V2)

In main2.xml there are apparently no errors. Same thing for main.xml however I think the problem lies here somewhere.
Quick Summary of what the app is: It is meant to use Google Maps onClick of a button but I am getting errors so I can just load the main menu on testing.
XML
I don't have enough rep to post picture so error pic can be found here
main2.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Club Deals"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="GPS locations" />
<Button
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Closest Deals"
android:onClick="open_close_deals" />
<Button
android:id="#+id/button6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cheapest Deals"
android:onClick="open_cheap_deals" />
<Button
android:id="#+id/button7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Best Value Deals"
android:onClick="best_value" />
<Button
android:id="#+id/button8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Best Events"
android:onClick="best_events" />
<Button
android:id="#+id/button9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="News"
android:onClick="news"/>
</LinearLayout>
AppActivity.java
In AppActivity I am given
"map cannot be resolved or is not a field" & "main2 cannot be resolved or is not a field"
package com.example.clubnightsdeals;
import android.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
public class AppActivity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), App2Activity.class);
startActivity(intent);
}
});
};
public void addListenerOnButtonNews() {
final Context context = this;
button = (Button) findViewById(R.id.button9);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(), App2Activity.class);
startActivity(intent);
}
});
};
/* protected void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
*/
// Google Map
GoogleMap googleMap;
protected void onCreate1(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
In App2Activity I am given the error "The import com.example.clubnightsdeals.R cannot be resolved"
App2Activity.java
package com.example.clubnightsdeals;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import com.example.clubnightsdeals.R;
public class App2Activity extends Activity {
Button button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
}
}
Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.clubnightsdeals"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/clubnightsdeals"
android:name=".AppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library
android:name="com.google.android.maps" />
<activity
android:label="#string/clubnightsdeals"
android:name=".App2Activity" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDetfYqNFORnvtR245fht3RIK25T6DRY" />
  <activity
            android:name="info.androidhive.googlemapsv2.MainActivity"
            android:label="#string/app_name"
            android:theme="#style/AppBaseTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>
</manifest>
You are pointing to wrong R.java file. Replace your following import line
import android.R;
with
import com.example.clubnightsdeals.R;
in your AppActivity.java file.
Your error shows that you have not closed the <activity> tag in your manifest file.
Make sure you have closed your activity tag as <activity android:name=""...../> or <activity android:name=""> </activity>
First remove
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
in manifest (cannot have 2 start activity in a App) then try to import R library.
If it still has this R error, check your xml files - make sure check all xml files.

Android GoogleMaps API v2 auth error, i do not get the error when running on an AVD but on my nexus 7 i get an auth error

I am developing an Android application which uses Google maps for android v2. The problem i having is that when i run it using the AVD in Eclipse i recieve no authentication error in the log cat output.
I am now testing my application on an Android tablet (nexus 7 2013) and i recieve this error when executing the application:
12-12 01:09:13.968: E/Google Maps Android API(14759): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
12-12 01:09:13.968: E/Google Maps Android API(14759): Ensure that the following correspond to what is in the API Console: Package Name: dcs.aber.ac.uk.cs211.group02, API Key: AIzaSyDcnzt6cdjEbCXSCRSTezmUHbaPW679if8, Certificate Fingerprint: 52FDB9ABBBAA062226834E35BF6A39FA2A3E27A7
I have tried to regen the API key, the one in the logcat matches the one provided in the google API console.
I have tried a clean project/clean install on the device several times, still no luck. The reast of the application works fine, only the map does not.
Here is my manifest.xml al the permissions seem ok.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dcs.aber.ac.uk.cs211.group02"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<permission
android:name="dcs.aber.ac.uk.cs211.group02.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<!-- Accessing camera hardware -->
<!-- putting android.hardware.camera prevents non-camera devices using this app -->
<uses-feature android:name="android.hardware.camera" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="dcs.aber.ac.uk.cs211.group02.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:logo="#drawable/ic_launcher"
android:theme="#style/AppTheme" >
<uses-library
android:name="com.google.android.maps"
android:required="true" />
<activity
android:name="dcs.aber.ac.uk.cs211.group02.StartScreen"
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="dcs.aber.ac.uk.cs211.group02.CreateWalkActivity"
android:label="#string/title_activity_create_walk" >
</activity>
<activity
android:name="dcs.aber.ac.uk.cs211.group02.HelpScreen"
android:label="#string/title_activity_help_screen" >
</activity>
<activity
android:name="dcs.aber.ac.uk.cs211.group02.WalkRecording"
android:label="#string/title_activity_walk_recording" >
</activity>
<activity
android:name="dcs.aber.ac.uk.cs211.group02.CreateNewPOIActivity"
android:label="#string/title_activity_create_new_poi" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDcnzt6cdjEbCXSCRSTezmUHbaPW679if8" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="dcs.aber.ac.uk.cs211.group02.ConfrimUploadActivity"
android:label="#string/title_activity_confrim_upload" >
</activity>
<activity
android:name="dcs.aber.ac.uk.cs211.group02.ServerResponse"
android:label="#string/title_activity_server_response" >
</activity>
</application>
</manifest>
This is the xml where the map is located:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
tools:context=".WalkRecording" >
<fragment
android:id="#+id/mapView"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="400dp" />
<ImageButton
android:id="#+id/walkRecordingHelpButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="16dp"
android:background="#color/transparent"
android:contentDescription="#string/helpIconAltText"
android:src="#drawable/help" />
<Button
android:id="#+id/walkRecordingNewPOIButton"
style="#android:style/TextAppearance.Small"
android:layout_width="85dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_below="#+id/mapView"
android:layout_marginBottom="8dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="8dp"
android:text="#string/walkRecordingNewPOIButtonText"
android:textColor="#color/light_gray" />
<Button
android:id="#+id/walkRecordingUploadButton"
style="#android:style/TextAppearance.Small"
android:layout_width="85dp"
android:layout_height="50dp"
android:layout_alignBaseline="#+id/walkRecordingNewPOIButton"
android:layout_alignBottom="#+id/walkRecordingNewPOIButton"
android:layout_alignParentRight="true"
android:layout_marginBottom="8dp"
android:layout_marginRight="15dp"
android:layout_marginTop="8dp"
android:text="#string/walkRecordingUploadButtonText"
android:textColor="#color/light_gray" />
</RelativeLayout>
And the code:
package dcs.aber.ac.uk.cs211.group02;
import java.util.Vector;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.maps.GeoPoint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
public class WalkRecording extends FragmentActivity {
private static String walkName, walkSDesc, walkLdesc;
private GoogleMap map;
private Context context;
private Button newPOIButton, uploadButton;
private ImageButton helpButton;
private static Vector<PointOfInterest> pois = new Vector<PointOfInterest>();
private CreateNewPOIActivity POIAct;
private final static int NEW_POI_REQ = 0;
private final static int EDIT_WALK_DETAILS = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_walk_recording);
context = this;
Bundle bundle = getIntent().getBundleExtra("Walk info");
if(bundle != null){
walkName = bundle.getString("walkTitle");
walkSDesc = bundle.getString("walkSdesc");
walkLdesc = bundle.getString("walkLDesc");
}
map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.mapView)).getMap();
map.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(52.4140,4.0810) , 14.0f));
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
POIAct = new CreateNewPOIActivity();
addOnClickListeners();
}
public void addOnClickListeners(){
helpButton = (ImageButton) findViewById(R.id.walkRecordingHelpButton);
helpButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, HelpScreen.class);
startActivity(intent);
}
});
newPOIButton = (Button) findViewById(R.id.walkRecordingNewPOIButton);
newPOIButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, CreateNewPOIActivity.class);
startActivityForResult(intent, NEW_POI_REQ);
}
});
uploadButton = (Button) findViewById(R.id.walkRecordingUploadButton);
uploadButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v){
Intent intent = new Intent(context, ConfrimUploadActivity.class);
Bundle b = new Bundle();
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.walk_recording, menu);
return true;
}
public void uploadTosever() {
}
public void deleteWalk() {
}
public double getLongitude() {
return 0;
}
public double getLattitude() {
return 0;
}
public static Vector<PointOfInterest> getPois() {
return pois;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == NEW_POI_REQ){
if( resultCode == RESULT_OK ) {
PointOfInterest p = data.getExtras().getParcelable("POIObject");
Toast lol = Toast.makeText(context, p.getName(), Toast.LENGTH_LONG);
lol.show();
pois.add(p);
Toast x = Toast.makeText(context, "POIS SIZE " + pois.size() , Toast.LENGTH_LONG);
x.show();
}
}
else if(requestCode == EDIT_WALK_DETAILS){
if( resultCode == RESULT_OK ) {
}
}
}
public static String getWalkName() {
return walkName;
}
public static void setWalkName(String walkName) {
WalkRecording.walkName = walkName;
}
public static String getWalkSDesc() {
return walkSDesc;
}
public static void setWalkSDesc(String walkSDesc) {
WalkRecording.walkSDesc = walkSDesc;
}
public static String getWalkLdesc() {
return walkLdesc;
}
public static void setWalkLdesc(String walkLdesc) {
WalkRecording.walkLdesc = walkLdesc;
}
}
Any ideas?
Resolved. alls it took was a device reset...

Unfortunately myandroidapps has stopped

I am very new to android apps development. I successfully signed my apps and installed on my phone Android Ver. 4.1.2. The codes below are my codes. May I know what is wrong? Thanks guys/girls :)
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/relativeLayout1"
>
<Button
android:id="#+id/buttonFlashlight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Torch" /> </RelativeLayout>
MainActivity.java
package com.mkyong.android;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
//flag to detect flash is on or off
private boolean isLighOn = false;
private Camera camera;
private Button button;
#Override
protected void onStop() {
super.onStop();
if (camera != null) {
camera.release();
}
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.buttonFlashlight);
Context context = this;
PackageManager pm = context.getPackageManager();
// if device support camera?
if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Log.e("err", "Device has no camera!");
return;
}
camera = Camera.open();
final Parameters p = camera.getParameters();
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (isLighOn) {
Log.i("info", "torch is turn off!");
p.setFlashMode(Parameters.FLASH_MODE_OFF);
camera.setParameters(p);
camera.stopPreview();
isLighOn = false;
} else {
Log.i("info", "torch is turn on!");
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(p);
camera.startPreview();
isLighOn = true;
}
}
});
}
}
myandroidapps Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" android:allowBackup="false">
<activity
android:label="#string/app_name"
android:name=".FlashLightActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application> </manifest>
you forget to declare MainActivity Activity in AndroidManifest.xml. add it as:
....
<activity android:name=".MainActivity" />
....
</application>
....

Why isnt my activity starting?

I think there is a problem with my activities because it runs the splash screen fine but when it gets to home page it gives force close error. I also appreciate it if you can see if my home.java code is correct I basically wanna open other activities and for exit button to quit the application.
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.decrypter"
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=".Splash"
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=".Home"
android:label="#string/title_activity_home" >
<intent-filter>
<action android:name="com.example.decrypter.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
home.java
package com.example.decrypter;
import android.os.Bundle;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.AdapterView.OnItemSelectedListener;
public class Home extends Activity implements OnItemSelectedListener {
Button btn_start,btn_about,btn_exit;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
btn_start = (Button) findViewById(R.id.btn_start);
btn_about = (Button) findViewById(R.id.btn_about);
btn_exit = (Button) findViewById(R.id.btn_exit);
btn_start.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
Intent start = new Intent(Home.this, MainPage.class);
Home.this.startActivity(start);
}
});
btn_about.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
Intent about = new Intent(Home.this, about.class);
Home.this.startActivity(about);
}
});
btn_exit.setOnClickListener( new View.OnClickListener()
{
public void onClick(View v) {
// TODO Auto-generated method stub
System.exit(0);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.home, menu);
return true;
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
String.xml
<string name="app_name">decrypter</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main_page">MainPage</string>
<string name="title_activity_home">Home</string>
<string name="prompt">- </string>
<string-array name="numbers">
<item >1</item>
<item >2</item>
<item>3</item>
<item >4</item>
<item>5</item>
<item >6</item>
<item >7</item>
<item >8</item>
<item>9</item>
</string-array>
home.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/btn_about"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/home" >
<Button
android:id="#+id/btn_start"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="183dp"
android:gravity="center"
android:text="Start" />
<Button
android:id="#+id/btn_about"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/btn_start"
android:layout_below="#+id/btn_start"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="About me" />
<Button
android:id="#+id/btn_exit"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/Button01"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:gravity="center"
android:text="Exit" />
</RelativeLayout>
In your main.java, either onClick or any other event, you have to call start activity for the home activity. Or if you want home activity to be the first to load then you can make home activity main and remove other main activities. Convert your Home activity to LAUNCHER activity.

Categories