search in another application - android

I want to know can ı search youtube or another application on my application.
String s=" hi ";
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/results?search_query=" + s));
startActivity(intent);
I can search using this code for youtube web site but I want to search in youtube android application (com.google.android.youtube ) . I will use below code for voice search .
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
mVoiceInputTv.setText(result.get(0));
String text =mVoiceInputTv.getText().toString();
String filename = text; // full file name
String[] parts = filename.split("\\ "); // String array, each element is text between spaces
String beforeFirstSpace = parts[0]; // Text before the first space
if(beforeFirstSpace.equalsIgnoreCase("Youtube")) {
Intent intent = new Intent(getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"));
intent.setAction(Intent.ACTION_SEARCH);
intent.putExtra(SearchManager.QUERY,text);
startActivity(intent);
finish(); System.exit(0);
}
With this code I open the youtube application but I can't search in application.

You can't do it easily since other apps may (and most likely) offer another API that is different than youtube.
For example:
youtube search API:
https://www.youtube.com/results?search_query=facebook
facebook search API:
http://www.facebook.com/search/web/direct_search.php?q=%gmail
gmail search API:
Gmail: http://mail.google.com/mail/?search=query&view=tl&start=0&init=1&fs=1&q=%youtube
You see there is a different pattern. Thus, you need to implement it manually, 1 by 1, and according to the search API offered by every single app.

Related

Add profile picture to contacts in Xamarin.Android

I am creating a hybrid mobile app, using Xamarin.Forms.
I want the user to click a button and the contact in the app gets inserted into the phone's contacts, including the profile picture.
So far, everything on the iOS side is working. I successfully insert the profile picture.
I can't get it to work on Android though. I've already tried looking on here but all solutions use Java. Inserting the name, number and e-mail works perfectly.
Here is my code so far:
public void SaveContacts(string name, string number, string email, string job, string company, byte[] imageData)
{
try
{
var intent = new Intent(Intent.ActionInsert);
intent.SetType(ContactsContract.Contacts.ContentType);
if (!string.IsNullOrWhiteSpace(name))
intent.PutExtra(ContactsContract.Intents.Insert.Name, name);
if (!string.IsNullOrWhiteSpace(number))
intent.PutExtra(ContactsContract.Intents.Insert.Phone, number);
if (!string.IsNullOrWhiteSpace(email))
intent.PutExtra(ContactsContract.Intents.Insert.Email, email);
if (imageData.Length != 0)
{
// INSERT PROFILE PICTURE HERE
}
Platform.CurrentActivity.StartActivity(intent);
}
catch (Exception ex)
{
DependencyService.Get<ILogger>()?.Error(ex);
}
}
How do I add the profile picture to the contact?
According to this case which is about Insert Contact (ContactsContract) via Intent with Image (Photo), you need to use the intent.putParcelableArrayListExtra(Insert.DATA, data) method to add the photo to the new contact.
But I have create a sample to test it. This method have a bug. I use the following code:
List<ContentValues> data = new List<ContentValues>();
ContentValues row1 = new ContentValues();
Intent intent = new Intent(Intent.ActionInsert);
intent.SetType(ContactsContract.Contacts.Photo);
intent.PutParcelableArrayListExtra(ContactsContract.Intents.Insert.Data, data);
But it will show the type convert error. Even though the class ContentValues is inherited from the IParcelable interface. The error still show. You can report it to the xamarin on the github.
In addition, I also try to use the method about using the content provider to insert a contact. But the RawContacts doesn't have ACCOUNT_TYPE property.
So for the bug, it seems you can't add profile picture to contacts with the native api.

UPI Deep Link - Unable to complete the transaction

Trying to connect the UPI payment using deeplink for my Android application, but every-time it fails at the last step.
The code fragment for the UPI payment call is below:
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
URI_URL = getUPIString("xxx#upi", "xxx xxx", "test_101", "Test Transaction", "10", "INR");
//Creating an intent for the UPI APP
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(URI_URL));
Intent chooser = Intent.createChooser(intent, "Pay the MSME by");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
startActivityForResult(chooser, 1, null);
}
}
});
To frame the UPI String using this function:
private String getUPIString(String payeeAddress, String payeeName, String trxnRefId,
String trxnNote, String payeeAmount, String currencyCode) {
String UPI = "upi://pay?pa=" + payeeAddress + "&pn=" + payeeName
+ "&tr=" + trxnRefId
+ "&tn=" + trxnNote + "&am=" + payeeAmount + "&cu=" + currencyCode;
return UPI.replace(" ", "+");
}
What could be the possible reasons of failure? Any suggestion or help is welcome.
The error is T04 meaning the refId should be alphanumeric with minlength 1 and maxlength 35. instead of test_101 use test101.
I have worked on UPI and integrate it into my Android project. I have also created a GitHub repository which can be useful for you.
Using deep linking, You will get mostly UPI supporting app but the problem is all app doesn't return value properly. I have tested Paytm, Google pay and freecharge and many more. But These app return value very well.
Due to this problem, I have created custom intent chooser so that exclude those apps who don't return value after payment. Along with this, you will get code of QR code to generate and scan UPI QR code.
Want to know more, here is a document.
Do check it and let me know, it helps you or not. Problem ask me.

Default image of App in Google Play is not shown while sharing using google PlusShare

When users tap G+ in the android App, It should fetch the image as shown in the document for PLUS SHARE. But it is not showing any image of my App.
Could you please let me know what fix is needed in my code
String value
<string name="plus_example_deep_link_id">
https://play.google.com/store/apps/details?id=com.egg.catcher.fun</string>
<string name="plus_example_deep_link_url">
https://play.google.com/store/apps/details?id=com.egg.catcher.fun
</string>
Code
private Intent getInteractivePostIntent() {
// Create an interactive post with the "VIEW_ITEM" label. This will
// create an enhanced share dialog when the post is shared on Google+.
// When the user clicks on the deep link, ParseDeepLinkActivity will
// immediately parse the deep link, and route to the appropriate
resource.
String action = "/?view=true";
/*
Uri callToActionUrl = Uri.parse(getString(R.string.plus_example_deep_link_url) + action);
String callToActionDeepLinkId = getString(R.string.plus_example_deep_link_id) + action;
*/
Uri callToActionUrl = Uri.parse(getString(R.string.plus_example_deep_link_url));
String callToActionDeepLinkId = getString(R.string.plus_example_deep_link_id);
// Create an interactive post builder.
PlusShare.Builder builder = new PlusShare.Builder(this);
// Set call-to-action metadata.
builder.addCallToAction(LABEL_VIEW_ITEM, callToActionUrl, callToActionDeepLinkId);
// Set the target url (for desktop use).
builder.setContentUrl(Uri.parse(getString(R.string.plus_example_deep_link_url)));
// Set the target deep-link ID (for mobile use).
builder.setContentDeepLinkId(getString(R.string.plus_example_deep_link_id),
null, null, null);
// Set the pre-filled message.
builder.setText(mEditSendText.getText().toString());
return builder.getIntent();
}

How to send file to google cloud printing app via intent in android 5?

I'm trying to tell the google cloud printing app to print a document, be it a .png file or an pdf. After checking if the app is installed via
public static boolean isCloudPrintInstalled(Context ctx){
String packageName = "com.google.android.apps.cloudprint";
android.content.pm.PackageManager mPm = ctx.getPackageManager();
try{
PackageInfo info = mPm.getPackageInfo(packageName, 0);
boolean installed = (info != null);
return installed;
}catch(NameNotFoundException e){
return false;
}
}
i send the user to the PrintingDialogActivity if it is missing, as described here: https://developers.google.com/cloud-print/docs/android
But i would like to use the app, if it is installed. If i send the following intent:
File theFile = new File(filePath); //file is NOT missing
Intent printIntent = new Intent(Intent.ACTION_SEND);
printIntent.setType(Helper.getMimeType(filePath));
printIntent.putExtra(Intent.EXTRA_TITLE, titleOfFile);
printIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(theFile));
ctx.startActivity(printIntent);
The getMimeType method is this:
public static String getMimeType(String url) {
String method = "Helper.getMimeType";
String type = null;
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
//Fix for Bug: https://code.google.com/p/android/issues/detail?id=5510
if(extension == null || extension.equals("")){
extension = url.substring(url.lastIndexOf('.'));
}
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
//should i consider just not using the MimeTypeMap? -.-
if(type == null || type.equals("")){
if(extension.toLowerCase(Locale.getDefault()).equals(".txt") == true){
type = "text/plain";
}else{
Log.e(method, "Unknown extension");
}
}
return type;
}
it returns "application/pdf" for pdf files.
On my android 4.0.3 device i get the action chooser and can choose the google cloud print app, which then allows to do stuff like saving the file to google drive. It works.
But if i start this intent on my Android 5.1.1 device (Nexus 5), the action chooser also opens, but it doesn't have the google cloud printing app or anything else printing related in it. Cloud print is preinstalled and currently on version 1.17b. I didn't kill it's process with some form of energy saving app. The device is not routed. What am i missing?
I also tried entering "text/html" by hand as the mime type, because that was the solution to another stackoverflow thread - but it doesn't solve mine.
Setting the mimetype to */* also doesn't make the actionchooser offer me the printer
After a lot of googling and testing it is rather unclear to me, if printing via intent is still possible on android 5 with google cloud print. BUT what does work is to create a custom PrintDocumentAdapter, as described in this post: https://stackoverflow.com/a/20719729/1171328

Get Voice input from Android Wearable

Currently applications like Google Hangouts and Facebook Messenger are able to accept voice input from Android Wearables, translate them to text and send reply messages to users. I have followed the tutorial at https://developer.android.com/training/wearables/notifications/voice-input.html and when I call the method outlined there:
private CharSequence getMessageText(Intent intent) {
Bundle remoteInput = RemoteInput.getResultsFromIntent(intent);
if (remoteInput != null) {
return remoteInput.getCharSequence(EXTRA_VOICE_REPLY);
}
}
return null;
}
I receive an error with the line RemoteInput.getResultsFromIntent(intent) stating that my API level is too low. Currently using a Samsung Galaxy S3, 4.4.2 API 19. Clearly, this method is not accessible to me, so my question is, how are applications like Hangouts and Facebook Messenger accepting voice input and getting that input onto my device?
developers.Android states that RemoteInput.getResultsFromIntent(intent); is a conveince so that we do not need to parse the ClipData, so I did some research and discorvered what exactly was needed to parse this ClipData and this is how I solved my Problem:
private void getMessageText(Intent intent){
ClipData extra = intent.getClipData();
Log.d("TAG", "" + extra.getItemCount()); //Found that I only have 1 extra
ClipData.Item item = extra.getItemAt(0); //Retreived that extra as a ClipData.Item
//ClipData.Item can be one of the 3 below types, debugging revealed
//The RemoteInput is of type Intent
Log.d("TEXT", "" + item.getText());
Log.d("URI", "" + item.getUri());
Log.d("INTENT", "" + item.getIntent());
//I edited this step multiple times until I discovered that the
//ClipData.Item intent contained extras, or rather 1 extra, which was another bundle
//The key for that bundle was "android.remoteinput.resultsData"
//and the key to get the voice input from wearable notification was EXTRA_VOICE_REPLY which
//was set in my previous activity that generated the Notification.
Bundle extras = item.getIntent().getExtras();
Bundle bundle = extras.getBundle("android.remoteinput.resultsData");
for (String key : bundle.keySet()) {
Object value = bundle.get(key);
Log.d("TAG", String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
tvVoiceMessage.setText(bundle.get(EXTRA_VOICE_REPLY).toString());
}
This answer should be useful for anyone that is interested in developing a wearable application using notifications and voice input replies prior to the release of Android-L.

Categories

Resources