【问题标题】:Android launchin thridparty intent not workingAndroid启动第三方意图不起作用
【发布时间】:2012-05-31 16:13:14
【问题描述】:

我正在尝试在单击按钮时启动相机应用程序,但我不想这样做 我希望它的行为就像是由 lauc´ncher 启动的,但是当我调用我的代码时,应用程序只是关闭并且相机没有启动。甚至没有错误代码。

代码:

if(v == camera)
    {

        //Intent in=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

            // this.startActivity(in);



        Intent startupIntent = new Intent();
        ComponentName distantActivity = new ComponentName("com.android.camera","com.android.camera/.Camera");
        startupIntent.setComponent(distantActivity);
        startupIntent.setAction(Intent.ACTION_MAIN);
        startActivity(startupIntent);    


        finish();
    }

【问题讨论】:

  • 确保你在清单中添加了
  • 我是否必须获得此权限才能仅启动意图?

标签: android android-intent camera


【解决方案1】:

使用android.intent.action.VIEW 代替Intent.ACTION_MAIN 作为:

    Intent startupIntent = new Intent();

    ComponentName distantActivity= new ComponentName("YOUR_CAMRA_APP_PACKAGE","YOUR_CAMRA_APP_PACKAGE.ACTIVTY_NAME");

// LIKE IN LG  DEVICE WE HAVE AS

//ComponentName distantActivity= new //ComponentName("com.lge.camera","com.lge.camera.CameraApp");

    startupIntent .setComponent(distantActivity);

    startupIntent .setAction("android.intent.action.VIEW");

    startActivity(startupIntent);

【讨论】:

  • 确定在运行此代码时会发生什么错误,然后发布您的 logcat 堆栈跟踪
  • android.content.ActivityNotFoundException:找不到明确的活动类 {com.android.camera/com.android.camera.Camera};您是否在 AndroidManifest.xml 中声明了此活动?
  • 你知道你的手机默认相机应用包名和主要活动名吗?
  • bez 在我的 lg 设备中,我有 com.lge.camera,只需将您的设备连接到 log cat 并在设备上启动相机应用程序即可确认
  • 但我怎样才能解决问题并获得正确的包名称?
猜你喜欢
  • 2016-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-25
相关资源
最近更新 更多