starting google earth with kml file - android

I'm trying to launch Google Earth 6.1 from my Android app with a specific KML file. Here is what I have:
File file = new File(Environment.getExternalStorageDirectory(), "master.kml");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.google-earth.kml+xml");
startActivity(intent);
My AndroidManifest.xml looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidscope"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
However, when I run I get an ActivityNotFoundException:
09-27 14:23:05.290: W/dalvikvm(3525): threadid=1: thread exiting with uncaught exception (group=0x400dc760)
09-27 14:23:05.290: E/AndroidRuntime(3525): FATAL EXCEPTION: main
09-27 14:23:05.290: E/AndroidRuntime(3525): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/master.kml typ=application/vnd.google-earth.kml+xml }
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1508)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1382)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Activity.startActivityForResult(Activity.java:3095)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.Activity.startActivity(Activity.java:3201)
09-27 14:23:05.290: E/AndroidRuntime(3525): at com.example.androidscope.MainActivity$1.onClick(MainActivity.java:85)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.view.View.performClick(View.java:3122)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.view.View$PerformClick.run(View.java:11942)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.os.Handler.handleCallback(Handler.java:587)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.os.Looper.loop(Looper.java:132)
09-27 14:23:05.290: E/AndroidRuntime(3525): at android.app.ActivityThread.main(ActivityThread.java:4028)
09-27 14:23:05.290: E/AndroidRuntime(3525): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 14:23:05.290: E/AndroidRuntime(3525): at java.lang.reflect.Method.invoke(Method.java:491)
09-27 14:23:05.290: E/AndroidRuntime(3525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
09-27 14:23:05.290: E/AndroidRuntime(3525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-27 14:23:05.290: E/AndroidRuntime(3525): at dalvik.system.NativeStart.main(Native Method)
I've noticed that if I add:
intent.setClassName("com.google.earth", "com.google.earth.EarthActivity");
then Google Earth loads but with no of the KML information. Does anyone have any ideas?

Uri earthURI = Uri.fromFile(kmlFile);
Intent earthIntent = new Intent(android.content.Intent.ACTION_VIEW, earthURI);
startActivity(earthIntent);

Intent earthIntent = new Intent(android.content.Intent.ACTION_VIEW, earthURI);
This seems to work fine on Android 5
Is there an Android 6 permissions change that breaks this intent?

Related

Google Maps Android API v2 application is crashing

I'm trying to get the sample code of Android 'Google Maps Android API v2' working. I get the project built without errors. However, when I try to run the app in Everpad device , the app crashes immediately.
here is :
- The java code
package com.dvp.android.gallery;
public class GPS extends Activity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions().position(KIEL).title("Kiel").snippet("Kiel is cool").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
The Manifest:
<application android:icon="#drawable/ic_bardo" android:label="#string/app_name">
<activity android:name=".Acceuil"
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=".Objets" android:label="Objets"> </activity>
<activity android:name=".GPS"
android:label="GPS">
</activity>
<activity android:name=".Detail" android:label="Detail"></activity>
<activity
android:name=".Galeries"
android:label="Galeries"
/>
<activity
android:name=".Evennements"
android:label="Evennements"/>
<activity
android:name=".Infos"
android:label="Infos"/>
</application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA0HMTTGLqlYaq6jOuS0imbjt7GmUHyK0c"/>
<uses-sdk android:minSdkVersion="11" />
<uses-permission android:name="com.dvp.android.gallery.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
The logcat output:
09-27 12:42:49.466: E/AndroidRuntime(5542): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dvp.android.gallery/com.dvp.android.gallery.GPS}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.access$600(ActivityThread.java:123)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.os.Looper.loop(Looper.java:137)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.main(ActivityThread.java:4429)
09-27 12:42:49.466: E/AndroidRuntime(5542): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 12:42:49.466: E/AndroidRuntime(5542): at java.lang.reflect.Method.invoke(Method.java:511)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-27 12:42:49.466: E/AndroidRuntime(5542): at dalvik.system.NativeStart.main(Native Method)
09-27 12:42:49.466: E/AndroidRuntime(5542): Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.Activity.setContentView(Activity.java:1835)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.dvp.android.gallery.GPS.onCreate(GPS.java:23)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.Activity.performCreate(Activity.java:4465)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
09-27 12:42:49.466: E/AndroidRuntime(5542): ... 11 more
09-27 12:42:49.466: E/AndroidRuntime(5542): Caused by: java.lang.RuntimeException: API key not found. Check that is in the element of AndroidManifest.xml
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bb.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bb.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.an.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bh.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at maps.ag.bg.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at bob.onTransact(SourceFile:107)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.os.Binder.transact(Binder.java:297)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.dynamic.a$4.b(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.dynamic.a.a(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:806)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1010)
09-27 12:42:49.466: E/AndroidRuntime(5542): at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1108)
the XML :
<LinearLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".GPS" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</LinearLayout>
Please help me . thanks
you just have to make your Activity extend FragmentActivity instead of Activity
This is because Google Map class has a fragment and for that you have to import android.support.v4. jar file... And add a map to your layout as a fragment you need to extends with FragmentActivity

Android - exception launching project on start after copying a lot of code over from another project

am getting this exception:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{business.premium/business.premium.Problemio}:
java.lang.ClassNotFoundException: business.premium.Problemio
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
... 11 more
java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
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:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
it says that class is not there, but it IS there. I tried to configure things in my project's build path, but not too sure what to tweak there.
And here is how I start my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="business.premium"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:name="MyApplication"
android:debuggable="true">
<activity
android:name=".Problemio"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any thoughts on how to solve this, or what to look into? Thanks!
Its because you specified the "android:name" attribute in the application node in the manifest file.
Do not use the android:name attribute!
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
This answer is taken from: java.lang.ClassNotFoundException on working app

Android map api cannot find com.google.settings

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapsandgps"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".Maps"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
i added also android api key but when program runs i get error
09-27 21:03:48.468: E/AndroidRuntime(215): Uncaught handler: thread main exiting due to uncaught exception
09-27 21:03:48.576: E/AndroidRuntime(215): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mapsandgps/com.example.mapsandgps.Maps}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.os.Handler.dispatchMessage(Handler.java:99)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.os.Looper.loop(Looper.java:123)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.main(ActivityThread.java:4363)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Method.invoke(Method.java:521)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-27 21:03:48.576: E/AndroidRuntime(215): at dalvik.system.NativeStart.main(Native Method)
09-27 21:03:48.576: E/AndroidRuntime(215): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.maps.MapView
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.Activity.setContentView(Activity.java:1622)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.example.mapsandgps.Maps.onCreate(Maps.java:24)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
09-27 21:03:48.576: E/AndroidRuntime(215): ... 11 more
09-27 21:03:48.576: E/AndroidRuntime(215): Caused by: java.lang.reflect.InvocationTargetException
09-27 21:03:48.576: E/AndroidRuntime(215): at com.google.android.maps.MapView.(MapView.java:237)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Constructor.constructNative(Native Method)
09-27 21:03:48.576: E/AndroidRuntime(215): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
09-27 21:03:48.576: E/AndroidRuntime(215): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
09-27 21:03:48.576: E/AndroidRuntime(215): ... 20 more
09-27 21:03:48.576: E/AndroidRuntime(215): Caused by: java.lang.IllegalArgumentException: You need to specify an API Key for each MapView. See the MapView documentation for details.
09-27 21:03:48.576: E/AndroidRuntime(215): at com.google.android.maps.MapView.(MapView.java:273)
09-27 21:03:48.576: E/AndroidRuntime(215): at com.google.android.maps.MapView.(MapView.java:254)
09-27 21:03:48.576: E/AndroidRuntime(215): ... 24 more
09-27 21:03:48.786: E/dalvikvm(215): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
you are probably trying to run the application in an incorrect version of target API on your virtual machine:
Select a target version that shows "Google APIs" in the beginig of the name-
good luck.
You are missing things in your manifest:
1) Permissions required by Google Maps (in <manifest>):
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
2) Meta data, last elements of <application> (ie after activities and services):
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key_goes_here" />
Refer to this documentation for further instruction.

Sending the user to another application

I have the following code in an activity to send the user to a different application:
public void goBack(View v) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(new ComponentName("com.example.android.lifecycle", "com.example.android.lifecycle.DialogActivity"));
startActivity(intent);
}
The manifest file for the application is:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.lifecycle"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />
<application android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
<activity android:name=".ActivityA"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="com.example.android.lifecycle" />
</intent-filter>
</activity>
<activity android:name=".ActivityB" />
<activity android:name=".ActivityC" />
<activity android:name=".DialogActivity"
android:theme="#android:style/Theme.Dialog">
<action android:name="com.example.android.lifecycle" />
<action android:name="android.intent.action.MAIN" />
</activity>
</application>
</manifest>
However, when I click on the button which should send me to the new application, I get a message saying - The application has stopped unexpectedly. Please try again.
What am I doing wrong and how can I rectify this?
Thanks!!
09-27 14:08:42.763: E/AndroidRuntime(286): FATAL EXCEPTION: main
09-27 14:08:42.763: E/AndroidRuntime(286): java.lang.IllegalStateException: Could not execute method of the activity
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View$1.onClick(View.java:2072)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View.performClick(View.java:2408)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View$PerformClick.run(View.java:8816)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Handler.handleCallback(Handler.java:587)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Handler.dispatchMessage(Handler.java:92)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Looper.loop(Looper.java:123)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.ActivityThread.main(ActivityThread.java:4627)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
09-27 14:08:42.763: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-27 14:08:42.763: E/AndroidRuntime(286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-27 14:08:42.763: E/AndroidRuntime(286): at dalvik.system.NativeStart.main(Native Method)
09-27 14:08:42.763: E/AndroidRuntime(286): Caused by: java.lang.reflect.InvocationTargetException
09-27 14:08:42.763: E/AndroidRuntime(286): at com.example.myfirstapp.DisplayMessageActivity.goBack(DisplayMessageActivity.java:30)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invokeNative(Native Method)
09-27 14:08:42.763: E/AndroidRuntime(286): at java.lang.reflect.Method.invoke(Method.java:521)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.view.View$1.onClick(View.java:2067)
09-27 14:08:42.763: E/AndroidRuntime(286): ... 11 more
09-27 14:08:42.763: E/AndroidRuntime(286): Caused by: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cmp=com.example.android.lifecycle/.DialogActivity } from ProcessRecord{450fce58 286:com.example.myfirstapp/10044} (pid=286, uid=10044) requires null
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Parcel.readException(Parcel.java:1247)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.os.Parcel.readException(Parcel.java:1235)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1298)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1373)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.Activity.startActivityForResult(Activity.java:2817)
09-27 14:08:42.763: E/AndroidRuntime(286): at android.app.Activity.startActivity(Activity.java:2923)
09-27 14:08:42.763: E/AndroidRuntime(286): ... 15 more
Add Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_FROM_BACKGROUND flags with intent if you are starting New Application from Background as:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(new ComponentName( "com.example.android.lifecycle","com.example.android.lifecycle.DialogActivity"));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);
I think in manifest file under activity android:name=".DialogActivity", the name should be
action android:name="com.example.android.lifecycle.DialogActivity"
Can you try?

Exception cast from a different project

Hey this is the weirdest problem i've ever encoutered,
I have 2 projects that's exactly the same each in a different project with a different package name.
Now i'm trying to run the 2nd project and i get a NullPointerException and when i press the error for it to send me to the line of code, it loads the same activity but in a different project.
Any idea why that happens?
This is my manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="shibby.koteret"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name=".TenKoteretActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/chosen_image" android:name="selectedImageActivity"
android:configChanges="keyboardHidden|orientation"
android:screenOrientation="portrait"
/>
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
Which is exactly the same in both projects besides package name and main activity name.
This is the logcat :
06-26 21:02:38.324: E/AndroidRuntime(5237): FATAL EXCEPTION: main
06-26 21:02:38.324: E/AndroidRuntime(5237): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1886, result=-1, data=Intent { dat=content://media/external/images/media/45 }} to activity {shibby.koteret/shibby.koteret.selectedImageActivity}: java.lang.NullPointerException
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.deliverResults(ActivityThread.java:2536)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.access$2000(ActivityThread.java:117)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.os.Handler.dispatchMessage(Handler.java:99)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.os.Looper.loop(Looper.java:123)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-26 21:02:38.324: E/AndroidRuntime(5237): at java.lang.reflect.Method.invokeNative(Native Method)
06-26 21:02:38.324: E/AndroidRuntime(5237): at java.lang.reflect.Method.invoke(Method.java:507)
06-26 21:02:38.324: E/AndroidRuntime(5237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-26 21:02:38.324: E/AndroidRuntime(5237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-26 21:02:38.324: E/AndroidRuntime(5237): at dalvik.system.NativeStart.main(Native Method)
06-26 21:02:38.324: E/AndroidRuntime(5237): Caused by: java.lang.NullPointerException
06-26 21:02:38.324: E/AndroidRuntime(5237): at shibby.koteret.selectedImageActivity.onActivityResult(selectedImageActivity.java:196)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.Activity.dispatchActivityResult(Activity.java:3908)
06-26 21:02:38.324: E/AndroidRuntime(5237): at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
06-26 21:02:38.324: E/AndroidRuntime(5237): ... 11 more
I don't think it's related, but as asked this is the relavent Java code (Errors on setContentView):
setContentView(R.layout.chosen_image);
ImageView imageView = (ImageView)this.findViewById(R.id.chosenImage2);
imageView.setImageBitmap(bitmap);
What i've checked :
The 2nd project packages the activity to the write project
I am not importing any thing from the 1st project package
Could this be an Eclipse error only? Anyone ever seen such a problem?
I was thinking, as the error is on an XML file, could it be somehow related to the R?
Well, what worked for me was i closed the 1st project and then Eclipse sent me to the right NullPointerException.
Still no idea why that happened, but that did the trick for me.

Categories

Resources