How can I create and start an Intent? - java

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

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);

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.

Related

How to make Custom popup look when send Intent in android

I`m new to android, I want to look like this custom popup intent
this is what I get my popup intent
here my question is how to add custom image and text in above popup when i try to share something via intent send.
this is my code what should I change here?
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
"Intall COC!!"+"https://play.google.com/store/apps/details?id=com.supercell.clashofclans");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Check your android version it's only supported start at android 11
use below code
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Here you can make custom title");
String shareMessage= "\nhere you can make custom message";
shareMessage = shareMessage + "Intall CoC!!\"+\"https://play.google.com/store/apps/details?id=com.supercell.clashofclans" + BuildConfig.APPLICATION_ID +"\n";
shareIntent.putExtra(Intent.EXTRA_TEXT, shareMessage);
startActivity(Intent.createChooser(shareIntent, "choose one"));

error in implimantation of intent

I have written the following code in java file in eclipse to make launch of snapchat application on my android device through my application. But when i am running it in my android device it shows "no apps can perform this action".
if(view.getId()==R.id.LaunchSnapchat){
intent= new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse("snapchat://details?id=com.snapchat.android&hl=en&rdid=com.snapchat.android"));
chooser=Intent.createChooser(intent,"Launch Snapchat");
startActivity(chooser);
}
what is the solution??
Simple answer, as taken from here
If you don't know the main activity, then the package name can be used to launch the application.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.snapchat.android");
if (launchIntent != null) {
startActivity(launchIntent);//null pointer check in case package name was not found
}
Try this
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.snapchat.android");
startActivity(Intent.createChooser(intent, "Open Snapchat"));
Also work this it is because mabe you did not have snapchat installed (emulator)
if(view.getId()==R.id.LaunchSnapchat){
intent= new Intent(android.content.Intent.ACTION_VIEW);
intent.setData(Uri.parse("snapchat://details?id=com.snapchat.android&hl=en&rdid=com.snapchat.android"));
chooser=Intent.createChooser(intent,"Launch Snapchat");
startActivity(chooser);
}

Intent betwen 2 applications

I ask if I can pass to an other application some data using intent. If it's possible, how can I do clicking a button and passing to an other application?
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intention = new Intent(?????);
startActivity(intention);
}
});
To pass data from one activity to another you need to add it to the Intent. E.g,
Intent intention = new Intent(this, DestClass.class);
int value = 10;
intention.putExtra("KEY", value);
startActivity(intention);
and in your DestClass's onCreate(), you get it from the Intent with,
Bundle extras = getIntent().getExtras();
if (extras!= null) {
extras.getInt("KEY");
}
To send it to another application. Similarly you create an Intent as shown in the Android docs.
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Note that in this case the Android system allows apps to register to receive Intents and if there are multiple apps that have registered for these Intents then the system lets the user choose which App they would like to handle the Intent.

How do i launch the music player

How am i suppose to use this
android.intent.category.APP_MUSIC
to launch the music player?
it doesn't work if i call makeMainSelectorActivity
Intent intent = new Intent();
intent.makeMainSelectorActivity(intent.ACTION_MAIN,
"android.intent.category.APP_MUSIC");
startActivity(intent);
This solution might help someone looking to launch default Music Player:
if(android.os.Build.VERSION.SDK_INT>=15){
Intent intent=Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,
Intent.CATEGORY_APP_MUSIC);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Min SDK 15
startActivity(intent);
}else{
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");//Min SDK 8
startActivity(intent);
}
Used below code :
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
or
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
startActivity(intent);
Ans also prefer url :
Launching the default music player

How to make a button that functions as a link in eclipse for android

I need to know how I could make a button that opens the androids web browser and navigates to a specific URL. I'm using eclipse and already know how to make buttons and click listeners.
Thanks for any help.
Just add this code to onClick():
// Launch a browser
Uri uri = Uri.parse("http://www.yahoo.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Intent websiteIntent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.android.com");
websiteIntent.setData(uri);
startActivity(websiteIntent);
Try this
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com");
startActivity(intent);

Categories

Resources