2016-11-04 186 views
0

我試圖模擬點擊錄製按鈕,當啓動MediaStore.ACTION_VIDEO_CAPTURE時。我的目標是讓應用程序在意圖啓動時立即開始錄製。但是當我運行我的代碼時,我得到以下內容注入到另一個應用程序需要INJECT_EVENTS權限Android

error: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission

。 INJECT_EVENTS權限只允許由系統應用程序。這是我的代碼:

Uri uri = Uri.fromFile(videoFile); 
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); 
videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 15); 
videoIntent.putExtra("android.intent.extras.CAMERA_FACING", 1); 
videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); 
startActivityForResult(videoIntent, videoRequest); 
new Thread(new Runnable() { 
    @Override 
    public void run() 
    { 
     Instrumentation inst = new Instrumentation(); 
     inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MEDIA_RECORD); 
    } 
}).start(); 

是否有另一種解決方案,當意圖啓動時開始記錄?

+0

檢查答案在https://stackoverflow.com/questions/22163424/android-java-lang-securityexception-injecting-to-another-application-requires/33489854,爲我工作 –

回答

相關問題