how to share images inside assets folder with intent to other application - android

i want to share images inside an assets folder using intent to the following applications
hangout
whatsapp
line chat
viber
tango
wechat
i have try this code for whatsapp but it given me file not supported
public void share (){
String file = "file:///android_asset/food/apple.png";
Uri filePath = Uri.fromFile(new File("content://com.example.zainabishaqmusa.postemoji/assets/gestures/aok.png"));
final ComponentName name = new ComponentName("com.whatsapp", "com.whatsapp.ContactPicker");
Intent oShareIntent = new Intent();
oShareIntent.setComponent(name);
//oShareIntent.setType("text/plain");
//oShareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Website : www.google.com");
oShareIntent.putExtra(Intent.EXTRA_STREAM, filePath);
oShareIntent.setType("image/png");
oShareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Gesture.this.startActivity(oShareIntent);
}

You would need a ContentProvider that is capable of sharing content from assets. My StreamProvider offers this, or you could write your own.

Related

Getting null.bin file after sharing a video in whatsapp from my app

I have stored a video file in the android raw folder and want to share it through WhatsApp. But I am getting the file in WhatsApp as null.bin.
private void shareVideo(){
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/raw/video_name");
Intent videoshare = new Intent(Intent.ACTION_SEND);
videoshare.setType("*/*");
videoshare.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
videoshare.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(videoshare);
}

I want to make android application to send picture, message to instagram users using instagram API

I've tried several sources from Google and GitHub but didn't find any authentic source that could help me sending multiple pictures and posts automatically from my android gallery using the scheduler. Is anyone working with the Instagram API? If so, could you please give me some authentic source?
Instead of using the Instagram API, you can directly start an Intent to post an Image or Video to Instagram by opening a "Share with" dialog. This will require user interaction.
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
Code example taken from https://www.instagram.com/developer/mobile-sharing/android-intents/

How to share text in Instagram

I need share text to instagram but I can't use android
intent.putExtra(Intent.EXTRA_TEXT,"MY TEXT");
nothing happen.please help me to do this
Instagram have stopped accepting pre-populated capitions to increase the quality of content in the system. See this post.
http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
Generic code for sharing text with any social app :
Step1 : Get the package name of app you wanna share :
To get the package name use adb logcat -s ActivityManager this command in windows and run the app like for example you want package name for instagram so run above command and open instagram app you would get the package name in logs
Note : the adb command listed above is for windows .
For ubntu you can use adb logcat | grep "ActivityManager"
STEP 2 : Once you got the package name of app below is generic code for sharing text .
try {
Intent shareOnAppIntent = new Intent();
shareOnAppIntent .setAction(Intent.ACTION_SEND);
shareOnAppIntent .putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_body));
shareOnAppIntent .setType("text/plain");
shareOnAppIntent .setPackage(PACKAGE_NAME_OF_APP);
startActivity(shareOnAppIntent );
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ShareAppActivity.this, "APP is not installed", Toast.LENGTH_LONG).show();
}
Unfortunately Instagram doesn't receives text from intent. it receives only EXTRA_STREAM object. you can share only images of format jpeg, gif, png. Since they are not providing any SDK you cant share in any other way.
Check Instagram developer documentation here they were clearly mentioning that the accepting Intent Parameter as EXTRA_STREAM
This is the code for sharing photo in Instagram
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
createInstagramIntent(type, mediaPath);
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
Here is the intent code to share image and text in Instagram.
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
shareIntent.putExtra(Intent.EXTRA_TEXT,"YOUR TEXT TO SHARE IN INSTAGRAM");
shareIntent.setPackage("com.instagram.android");
return shareIntent;

File sharing using Intent.ACTION_SEND gives access denied on BBM

I am trying to share an audio file saved by my application. The file is added to the media store so all apps can access it.
Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri fileContentUri = Uri.fromFile(finalFile);
mediaScannerIntent.setData(fileContentUri);
this.sendBroadcast(mediaScannerIntent);
I use Intent.ACTION_SEND to share the files to other apps:
public void shareRecording(View view) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setType("audio/mp3");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + recording.getFilePath()));
try {
startActivity(Intent.createChooser(i, "Share " + recording.getName()));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no app installed to share your audio file.", Toast.LENGTH_SHORT).show();
}
}
All working good with all apps like GMail, Yahoo mail, Whatsapp, ...
except BBM, it gives access denied.
What do I need to do to make it work on BBM ?
Thanks for any help.
UPDATE:
I used
Uri fileUri = Uri.parse("content://" + recording.getFilePath());
instead of
Uri fileUri = Uri.parse("file:///" + recording.getFilePath());
and it worked on BBM but not othe apps
So what is the difference between havin the URI parsed with: "file:///" and "content://" ?
And how can I used this to get the share working for all apps ?
The solution is to use the actual file to initialize the Uri object.
File recordingFile = new File(recording.getFilePath());
Uri fileUri = Uri.fromFile(recordingFile);
This worked with all the apps that can share a file.

How do I determine if Android can handle PDF

I know Android cannot handle PDFs natively. However, the Nexus One (and possibly other phones) come pre-installed with QuickOffice Viewer. How would I determine whether the user has a PDF viewer installed?
Currently, the code to start the PDF download looks pretty simple:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
After the download, the user clicks on the downloaded file to invoke the viewer.
However, if there is no PDF viewer, Android reports "Cannot download. The content is not supported on the phone."
I want to determine if the user will get this message, and if so, direct them to PDF apps in the Android Market.
I have been testing this and found that the following works. First you download the file independently and store it on the device and then you go do this:
File file = new File("/sdcard/download/somepdf.pdf");
PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0 && file.isFile()) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
I have tested this on various emulator and a rooted cyanogen phone as well as a HTC Magic. If no pdf renderer is available the list will return zero and nothing will happen.
It seems to be important to set the data type to the pdf mime type to get the correct behaviour.
If you e.g. install droidreader it will react to the intent and display the pdf.
Of course you could do the check before you download the pdf as well depending on your use case or do things like popping up alerts or redirecting do other intents for download or whatever.
Edit: I have since refactored this out into a separate method ..
public static final String MIME_TYPE_PDF = "application/pdf";
/**
* Check if the supplied context can render PDF files via some installed application that reacts to a intent
* with the pdf mime type and viewing action.
*
* #param context
* #return
*/
public static boolean canDisplayPdf(Context context) {
PackageManager packageManager = context.getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType(MIME_TYPE_PDF);
if (packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0) {
return true;
} else {
return false;
}
}
You can query the PackageManager to see if there's a package that can handle your Intent. Here's an example: http://www.curious-creature.org/2008/12/15/android-can-i-use-this-intent/
You will probably use asynch task to download any file.so simple way is Just add below code in post execute() method of asynch task.it will ask for choice.
FileOpener.open(context, file);
and file should contain info about filepath and filename.Example
File file = new File(Environment
.getExternalStoragePublicDirectory("/MDroid")
+ filepath + fileName );
Hope it helps

Categories

Resources