In my very simple app (based on the default Hello World app but with a button added) I try to open one of my phone's (a SE X10 Mini) preinstalled activities, like this:
Intent calendarIntent = new Intent();
calendarIntent.setClassName("com.sonyericsson.calendar","com.sonyericsson.calendar.dayview.DayActivity");
startActivity(calendarIntent);
However, it does not work, I get the following error in the log:
E/AndroidRuntime( 2215): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.sonyericsson.calendar/.dayview.DayActivity } from ProcessRecord{302cf238 2215:com.klibb.quickappointment/10079} (pid=2215, uid=10079) requires null
E/AndroidRuntime( 2215): at an开发者_运维问答droid.os.Parcel.readException(Parcel.java:1246)
E/AndroidRuntime( 2215): at android.os.Parcel.readException(Parcel.java:1234)
E/AndroidRuntime( 2215): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:1157)
E/AndroidRuntime( 2215): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1449)
E/AndroidRuntime( 2215): at android.app.Activity.startActivityForResult(Activity.java:2661)
E/AndroidRuntime( 2215): at android.app.Activity.startActivity(Activity.java:2705)
E/AndroidRuntime( 2215): at com.klibb.quickappointment.QuickAppointmentActivity$1.onClick(QuickAppointmentActivity.java:25)
Is there anything I can do about this or is this type of code a no-no? When searching the web I see people changing the intent filters in what I assume is their own app, but I obviously cannot change anything in a preinstalled app.
Any ideas are welcome!
PS. What I am trying to achieve is to create a small program that directly launches the "New Apppointment" activity of my phone, to avoid going through two extra activities (start the default calendar, click a day, click an hour).
Mathias,
What you are trying to do is actually very simple. However, the information you need may be hard to get. You need to find three pieces of information (none of which require rewriting the pre-installed app)
1)Determine if the activity can be started by external components. This is done by using the Package Manager to provide you a list of all installed packages and their related data. You could also get a free package analyzer from the Android Market. 2)Get the permission required to start the app and add it to your manifest. Permissions are registered with Android OS, but getting required permissions for an external app is not done through the package manager, as far as I know. 3)Get the Intent Extras (data) required to start the activity if it is a "sub activity".
Your best bet for #2 & 3 are to contact Sony Ericsson or search on their website. Many Android phone manufacturers do provide open information about their products. If you are lucky, it may be a simple as including a file that they provide you via AIDL.
FuzzicalLogic
You have to have android.permission.READ_CALENDAR
permission listed in the manifest. Some others may be required as well.
精彩评论