intent to youtube app profile/channel - java

I am able to intent to the youtube app to view a video easily enough, but how about getting to a profile / channel?
public void YouTube(String id) {
// Play Youtube Video
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:"+id));
mContext.startActivity(i);
}
I.. just don't know where to really begin here? Is there a specific Uri to parse? I've tried scouring the internet of course and I'm coming up dry for answers. Is it even possible in the first place?
Thanks guys!

By doing the following ,one can launch Youtube App to display channel directly
Intent intent=null;
try {
intent =new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.google.android.youtube");
intent.setData(Uri.parse(url));
startActivity(intent);
} catch (ActivityNotFoundException e) {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
And in order to display channel,keep in mind to give url in format http://www.youtube.com/user/channelName

As of now, there is no specific URI scheme for channels that would trigger the YouTube application directly. The vnd.youtube scheme is defined only for the activity that plays a single video. So, you have to specify the canonical YouTube URL for the channel page, and typically let the user pass through the application chooser dialog - assuming that the device has the YouTube application installed, the dialog would display at least two entries, the second being for the browser.

Related

How do I verify if my share app link is working in android studio before publshing app?

I have added a share app button and link to my app made in android studio but I'm not sure if this is the way it should work as I have checked other apps' share options and they tend to give the user an option on where exactly they'd like to share their application, while my link sends the user straight to the app page. I found this method on another thread made on this website but I'm not sure if it works properly as I haven't published my app yet. Can someone verify if this is the most popular method to share apps and if not can someone redirect me to where I can find the best solution for a share app option.
segment of my MainActivity.java code regarding the share method:
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_share:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.mydomain.tapp"));
startActivity(intent);
break;
}
drawerLayout.closeDrawer(GravityCompat.START);
return true;
}
You are using the wrong Intent Action for your requirement. Your requirement is to share your app's PlayStore link with another person. So, you have to use ACTION_SEND.
ACTION_VIEW is used to display the data to the user.
ACTION_SEND is used to deliver some data to someone else.
For example,
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
intent.putExtra(Intent.EXTRA_TEXT, "http://play.google.com/store/apps/details?id=com.mydomain.tapp");
startActivity(intent);

How to link my app with WhatsApp when WhatsApp Business is also on the device?

WhatsApp Business opens in place of WhatsApp. How can I link only to WhatsApp?
Here is the code:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send phone="+phonestr+"&text="+messagestr));
startActivity(i);
You can set the target package (application ID) that you want to handle the intent using Intent.setPackage.
But if the package is not installed it will throw an exception so keep in mind to handle that as well.
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://api.whatsapp.com/send phone="+phonestr+"&text="+messagestr));
i.setPackage("com.whatsapp");
startActivity(i);
In addition you can try different packages after getting ActivityNotFound exception. For example try WhatsApp and if it threw an Exception, then try WhatsApp Business or whatever

How to call intent method from java using flutter

So I am trying to make my app auto-start So to do this i have to redirect the user to the auto start screen of the devices. I tried calling intent similar as we get the battery detail app in flutter but it's not working, how to make app autostart any guidance will be helpful.github issue
what I am looking for an alternate way of using
this intent to open auto-start screen in oppo
Intent intent = new Intent();
intent.setClassName("com.coloros.safecenter",
"com.coloros.safecenter.startupapp.StartupAppListActivity");
startActivity(intent);
this is for Xiaomi
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.miui.securitycenter",
"com.miui.permcenter.autostart.AutoStartManagementActivity"));
startActivity(intent)
this intent in flutter. I already looked into flutter intent
I got your question. You can try the following for Xiaomi devices
static const platform = const MethodChannel('com.myapp/intent');
void openAutoStartSettings() async {
await platform.invokeMethod('com.miui.permcenter.autostart.AutoStartManagementActivity');
}
For other manufacturers, please check this post https://tutel.me/c/programming/questions/48166206/how+to+start+power+manager+of+all+android+manufactures+to+enable+background+and+push+notification
I'm not sure what you are asking but to start an app from a flutter app you can use this package:
https://pub.dev/packages/flutter_appavailability
here an exemple to open the mailBox app
try{
AppAvailability.launchApp(Platform.isIOS ? "message://" : "com.google.android.gm").then((_) {
print("App Email launched!");
}).catchError((err) {
print(err);
});
} catch(e) {
print(e);
}
You can use android_intent library for launching external app. Documentation has some sample codes.
You may use sample code below.
var map={"AuthParams":authParam};
var intent=AndroidIntent(package:"in.app",arguments: map,componentName: "in.app.ui.splash.SplashActivity",/*action: "action_view"*/);
await intent.launch();

How to open default email client in Android, without sending a message?

I'm looking for a way to open default email application on Android, but without using it to send a message. I know I can do this using mailto:// or intent params, but this automatically opens new message screen. What I want to to archieve, is just opening the app itself.
So far, I have tried
override fun startEmailApplication() {
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_EMAIL)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
But every time I get
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW cat=[android.intent.category.APP_EMAIL] flg=0x10000000 }
Altrough an email app (AquaMail, Outlook) is installed.
I would use a combinaison a little things.
Detect the responding packages for a given Intent:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setType("text/plain");
List<ResolveInfo> resolveInfos = getPackageManager().queryIntentActivities(intent, 0);
boolean canResolve = resolveInfos.size() > 0;
This will list the available packages to respond to such Intent. Using queryIntentActivities() allows me to retrieve ResolveInfo which exposes more information about the app.
Select the first one and open it using its packageName:
if (resolveInfos.size() > 0) {
startActivity(getPackageManager().getLaunchIntentForPackage(resolveInfos.get(0).resolvePackageName))
}
You also won't have the ActivityNotFoundException because we check before hand that something will respond to our Intent. Feel free to handle the failing case in a else.
You can do the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_EMAIL);
getActivity().startActivity(intent);

populating SMS message in android

Here is the code snippet from our app now.
public void onClick(View v) {
// TODO Auto-generated method stub
Intent sms = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" ));
sms.putExtra("sms_body", text);
startActivity(sms);
}
This works with the stock SMS app, however a tester reported that with handcent SMS they get a blank message. This prompted me to try it with Google Voice, also get a blank message there.
Is there some way I can get my message text to work with all of these other SMS apps?
We have a clipboard functionality, so a poor workaround at least would be having user push clipboard button, then use their messaging app of choice.
Android tries to reuse Intents as much as possible. In some cases when you start an intent, android doesn't create a new Intent and reuse previous intents. To avoid this set this flag of Intent:
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
This flag forces Android to create a new Task with the intent's Activity on top of stack.
When you pass this intent , this will be delivered to all those apps which have registered an activity to receive it. In otherwords you have to use the intent that is registered by the application that u intent to handle your intent

Categories