How can I create and start an Intent?

筅森魡賤 提交于 2019-12-12 02:56:43

问题


I was wondering how I can create and start an intent using this:

"qsrtech.posprintdriver/.printservice"

I downloaded the POS Printer Driver (ESC) app (which is the app I am trying to access).

I tried this:

        String PrintPage = "qsrtech.posprintdriver/.printservice";
        Intent intent = new Intent(Intent.ACTION_MAIN);             
        intent.setComponent(ComponentName.unflattenFromString(PrintPage));             
        intent.addCategory(Intent.CATEGORY_LAUNCHER );             
        startActivity(intent); 

However, I get an error saying: "No activity found to handle this intent"

I was wondering if there is anything I can do to access this intent? The thing is that I'm not sure if I'm accessing an activity or a background service (probably an intent service?) from a different app.

Here is the link that explains more about this intent. http://www.qsrtechnologies.com/aboutposdriver.html


回答1:


You can try with this :

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra("Data", "Test printer\n\n");
sendIntent.setComponent(new ComponentName("qsrtech.posprintdriver","qsrtech.posprintdriver.printservice"));
startService(sendIntent);



回答2:


Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra("Data", "Test printer\n\n");
sendIntent.setComponent(new ComponentName("qsrtech.posprintdriver","qsrtech.posprintdriver.printservice"));
startService(sendIntent); 

Worked like a charm here.



来源:https://stackoverflow.com/questions/16904676/how-can-i-create-and-start-an-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!