-->

How can I create and start an Intent?

2019-08-28 05:03发布

问题:

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.