I can open TikTok to a user's profile with the below code, but how do I open TikTok to its Homepage?
Uri uri = Uri.parse("https://vm.tiktok.com/"+"tiktokExtension");
Intent tiktokIntent = new Intent(Intent.ACTION_VIEW, uri);
tiktokIntent.setPackage("com.zhiliaoapp.musically");
startActivity(tiktokIntent);
you start tiktok application this way :
try{
Intent intent = new Intent("com.zhiliaoapp.musically");
startActivity(intent);
}catch(ActivityNotFoundException e){
//if the app doesn't exist do some stuff , like redirection to playstore.....
}
Related
I'm coding an android - java app which can open a Facebook post url
(ex: https://www.facebook.com/BaHangXom.0/videos/2377836809193490).
I tried some ways to start Facebook app with intent but unsuccessfully.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=" + "https://www.facebook.com/BaHangXom.0/videos/2377836809193490"));
intent.setPackage("com.facebook.katana");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Could you please give me any idea?
Thank you so much.
Simply open the url:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/BaHangXom.0/videos/2377836809193490"));
startActivity(intent);
This is the most simple and universal way: user will be able to choose (and remember the choice) whether they want to open the link via main Facebook app, Facebook lite, or the browser.
You can open the facebook app using this code:
public static Intent newFacebookIntent(PackageManager pm, String url) {
Uri uri = Uri.parse(url);
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0);
if (applicationInfo.enabled) {
// http://stackoverflow.com/a/24547437/1048340
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
}
} catch (PackageManager.NameNotFoundException ignored) {
}
return new Intent(Intent.ACTION_VIEW, uri);
}
I want to choose a file via an Android File Manager.
so, to open file intent code is
Intent intent = new Intent();
intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select File"), 1);
But I was unable to access file manager in samsung devices to resolve this problem i do
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, 1);
But this code in not working in other devices so what should i do to open file manager in all devices ?
private void openFile(int requestCODE) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("*/*");
startActivityForResult(intent, requestCODE);
}
In my application after button click I want to show chooser of available photo applications in my app. The goal is to pick image from one of the photo-related apps and show it in my app.
After button click following method is being executed:
private void fireIntentToOpenDeviceImageResources() {
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContext().getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent, takePicture});
startActivityForResult(chooserIntent, GlobalConsts.PICK_IMAGE_REQUEST);
}
The problem is that I don't see dropbox app (it is for sure installed in my testing phone) in created chooser. What kind of intent I should add in order to include dropbox app?
EDIT:
I added such intent:
PackageManager manager = getActivity().getPackageManager();
Intent i = manager.getLaunchIntentForPackage("com.dropbox.android");
i.setAction(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Now it shows dropbox app in chooser but I can't pick the image from it. It simply launches dropbox app without picking and returning to my app possibility.
Android 4.4 (API level 19) introduces the Storage Access Framework (SAF), with a centralized document access. You can open to the document chooser with this simple code:
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
startActivityForResult(getIntent, MY_REQUEST_CODE);
For this reason on Android >=19 your code will open the intent chooser with various app, for example Camera, Photos (etc, etc... depends on what apps are installed) and Documents. If you select Documents the document chooser will open and on the sidebar there are all the different apps installed in your device, including Dropbox.
If you want that Dropbox will be directly available in the intent chooser you can change your code like this:
private void fireIntentToOpenDeviceImageResources() {
Intent pickIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
Uri imageUri = MainActivity.this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
takePicture.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
Intent dropboxIntent = new Intent(Intent.ACTION_GET_CONTENT);
dropboxIntent.setPackage("com.dropbox.android");
dropboxIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(pickIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takePicture, dropboxIntent});
startActivityForResult(chooserIntent, GlobalConsts.PICK_IMAGE_REQUEST);
}
Warning! With this technique you need to manually add every app that it was available only in the document chooser, for example if you want to add also ES File Manager you need to create the intent and add to the list of EXTRA_INITIAL_INTENTS:
Intent esFileManagerIntent = new Intent(Intent.ACTION_GET_CONTENT);
esFileManagerIntent.setPackage("com.estrongs.android.pop");
esFileManagerIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(pickIntent, "Select Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{takePicture, dropboxIntent, esFileManagerIntent});
I have a facebook page and want to open it through the Facebook App and not through the browser. How to do so ?
For example the amazon page which is: https://www.facebook.com/Amazon
I tried this:
String uri = "facebook://facebook.com/amazon";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
This opens the Facebook App but now the facebook page.
Thanks!
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/"+FB_ID));
//or Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/"+FB_ID));
startActivity(intent);
where FB_ID - ID of group
Okay I solved it. Had to use this:
"fb://page/9465008123"
I am trying to launch an email intent with an attached jpg.
I did:
Intent intent4 = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto", "testemail#gmail.com", null));
startActivity(intent4);
this launches the email activity.
But when I try to add DataAndType (my jpeg attachment). It fails with
android.content.ActivityNotFoundException: No Activity found to handle Intent { action=android.intent.action.SENDTO data=file:///data/data/com.mycompany.mypackage/files/temp-picture type=JPEG
Intent intent4 = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto", "testemail#gmail.com", null));
intent4.setDataAndType(Uri.parse("file://"+ mTempFilePath),
Bitmap.CompressFormat.JPEG.name());
startActivity(intent4);
Did you try setting the mime manually to "image/jpeg" instead of Bitmap.CompressFormat.JPEG.name().