2012-05-31 83 views
0

我試圖啓動相機應用程序上的按鈕點擊,但我不想hav該fot 我希望它的行爲像它是由lauc'ncher啓動,但當我打電話我的代碼應用程序簡單地關閉和相機不啓動。甚至沒有錯誤代碼。Android啓動thridparty意圖不起作用

代碼:

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(); 
    } 
+0

請確保您有添加<使用許可權的android:NAME = 「android.permission.CAMERA」/>在清單? –

+0

我是否必須獲得此許可才能啓動該意圖? – user1426956

回答

0

使用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); 
+0

也不能正常工作:( – user1426956

+0

確定當你運行這段代碼時發生了什麼,然後發佈你的logcat stacktrace –

+0

android.content.ActivityNotFoundException:無法找到顯式活動類{com.android.camera/com.android.camera .Camera};你有沒有在你的AndroidManifest.xml中聲明這個活動? – user1426956