0

我似乎遇到了两个问题。第一种情况是当我启动时钟应用程序并完美运行时,这似乎是我启动大多数应用程序时的情况。

第二种情况是当我尝试启动诸如电话活动之类的活动时。当我去获取 Intent 时,getLaunchIntentForPackage(app.pname) 返回 null。是否有不同的方法来获取电话活动的 Intent 以便我可以在这种情况下启动它?

第三种情况是我去启动一个活动,比如相机活动。看来我必须在我的 androidManifest.xml 文件中已有 Camera 活动才能启动它,但是还有其他方法可以解决这个问题吗?我的应用程序能够从其 UI 启动任何应用程序,因此我无法事先将 android 设备的每个活动都添加到我的清单文件中。谢谢!

爪哇:

        Intent launchApp = getPackageManager().getLaunchIntentForPackage(app.pname);

            System.out.println(Intent of " + appName + ": + " " +launchApp);

            if(launchApp!=null){
                System.out.println("Permission granted to launch " + appName);
                startActivity( launchApp );
            }

            else{

                System.out.println("Permission not granted to launch " + appName);
            }

日志猫:

        08-07 09:38:57.031: I/System.out(1056): Intent of Clock: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.htc.android.worldclock/.WorldClockTabControl }
        08-07 09:38:57.041: I/System.out(1056): Permission granted to launch Clock
        08-07 09:38:59.783: I/System.out(1056): Intent of Phone: null
        08-07 09:38:59.783: I/System.out(1056): Permission not granted to launch Phone
        08-07 09:39:10.564: I/System.out(1056): Intent of Camera: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.camera/com.android.internal.app.ResolverActivity }
        08-07 09:39:10.574: I/System.out(1056): Permission granted to launch Camera
        08-07 09:39:10.574: D/AndroidRuntime(1056): Shutting down VM
        08-07 09:39:10.574: W/dalvikvm(1056): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
        08-07 09:39:10.614: E/AndroidRuntime(1056): FATAL EXCEPTION: main
        08-07 09:39:10.614: E/AndroidRuntime(1056): java.lang.IllegalStateException: Could not execute method of the activity
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.view.View$1.onClick(View.java:2191)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.view.View.performClick(View.java:2532)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.view.View$PerformClick.run(View.java:9293)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.os.Handler.handleCallback(Handler.java:587)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.os.Handler.dispatchMessage(Handler.java:92)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.os.Looper.loop(Looper.java:150)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.app.ActivityThread.main(ActivityThread.java:4306)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at java.lang.reflect.Method.invokeNative(Native Method)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at java.lang.reflect.Method.invoke(Method.java:507)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at dalvik.system.NativeStart.main(Native Method)
        08-07 09:39:10.614: E/AndroidRuntime(1056): Caused by: java.lang.reflect.InvocationTargetException
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at          java.lang.reflect.Method.invokeNative(Native Method)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at java.lang.reflect.Method.invoke(Method.java:507)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.view.View$1.onClick(View.java:2186)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     ... 11 more
        08-07 09:39:10.614: E/AndroidRuntime(1056): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.camera/com.android.internal.app.ResolverActivity}; have you declared this activity in your AndroidManifest.xml?
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1565)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1539)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.app.Activity.startActivityForResult(Activity.java:2919)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at android.app.Activity.startActivity(Activity.java:3025)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     at com.worklight.androidnativeapp.AndroidNativeApp.appClicked(AndroidNativeApp.java:284)
        08-07 09:39:10.614: E/AndroidRuntime(1056):     ... 14 more
4

1 回答 1

1

如何启动相机

如何启动拨号程序

要启动特定的应用程序,您需要知道包名和类名

try{
    Intent i = new Intent();
    i.setClassName("com.example.app", "com.example.app.MainActivity");
    i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(e);
}catch(ActivityNotFoundException e){
    e.printStackTrace();
}
于 2013-08-07T14:07:55.720 回答