I am trying to make it so a user can select a gif in my app and send it through a text message. From what I have, you can click on a gif, then the app allows you to choose a messaging platform and starts a new message, but gives the error "Unable to attach. File not supported." and won't attach the gif to the text message. How should I go about fixing this?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View imageView, int position, long id) {
Toast.makeText(getApplicationContext(), "Pick a messenger!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_SEND);
File f = new File("/res/drawable/broke.gif");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
intent.setType("image/gif");
startActivity(Intent.createChooser(intent, "Send"));
}
});
}
broke.gif is the gif I have been trying to send while testing my program.
You have two problems.
First, as Gabe notes, fewer apps than you might expect will support GIF.
However, you have a bigger problem:
File f = new File("/res/drawable/broke.gif");
There is no /res/drawable/broke.gif on the Android device.
Presumably, you mean "the drawable in my project named broke.gif". Resources are files on your development machine. They are not files on the device. They are entries in the ZIP archive that is the APK file.
Sharing a drawable resource is at least theoretically possible, such as using my StreamProvider.
Related
It might be a very simple question for some of you. I have a button, on click of which I can attach single or multiple file and I am accessing the file paths in OnActivityResult(). Using (Intent.EXTRA_ALLOW_MULTIPLE, true) has let me attach multiple files now. The issue is now I can't select a single file if I want to and have to always select multiple files for the opperation. I am not doing it for sending a mail. Its a simple process of selecting some files and based on the selection, get the corresponding data from the SD card and upload.
Below I am posting my code for opening the browser and attach files :
txtv_attach.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v)
{
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.putExtra(Intent.EXTRA_STREAM, uri);
chooseFile.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
chooseFile.setType("*/*");
chooseFile = Intent.createChooser(chooseFile, "Choose a file");
startActivityForResult(chooseFile, PICKFILE_RESULT_CODE);
}
});
Is there any way I can attach both single as well as multiple files? need your help. Thanks in advance.
I have a gridview of gifs that I am displaying, and I want the user of the app to be able to select one and have it copied and saved into the user's clipboard so they could paste it manually into a text message. Right now, I am attempting to do this by referencing the gif as a Uri and putting the Uri into the Clipboard. I got my code to work using a string of text, but I cannot get it to copy the Uri of a gif. I am unsure where I am off, as I could be just referencing the Uri incorrectly, or going about it completely wrong.
Heres the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
copy = (Button) findViewById(R.id.copy);
copy.setOnClickListener(this);
}
#Override
public void onClick(View gridview){
Uri copyUri = Uri.parse("android.resource://com.example.eric.hellogridview/drawable/broke");
ClipData theClip = ClipData.newUri(getContentResolver(), "broke", copyUri);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(theClip);
Toast.makeText(getApplicationContext(), "Copied to Clipboard", Toast.LENGTH_SHORT).show();
}
I'm affraid to tell you it's impossible.
You can copy the image to phons external memory and let the user to access it from there.
There is an option to build for spesific manufactors who useing hidden API, But its seem to be too complicated and nasty.
I have reviewed and tried numerous versions of this issue to no avail. I have seen answers as far back as 2011 and as recent as mid-year 2014. Unfortunately, the many partial answers and poorly explained suggestions have created more questions than answers. I have an Apple App available in the iTunes App Store that performs all that I am trying to do with this Android App. In the Apple App world viewing a pdf file is relatively easy to perform but I am having a very difficult time accomplishing it in Android. I admit that I am very limited in my experience at creating Android Apps.
The problem is that I have an Android App with a main activity that has a ListView that lists the titles for about 35 diagrams in pdf format. Each of these is clickable for viewing in a full screen activity (view). Each pdf is half page width and anywhere from 1/2 a page to two pages in length. So the new activity (pdf view) will need to be scrollable. Since this is an app for phones or pads the new activity (pdf view) needs to be zoomable. After the user completes their view of the pdf they will need an option to return to the main activity. The user can then select another diagram for viewing.
The things I have already accomplished are:
- ListView of diagram titles on main activity
- Listener enabled for each entry in ListView
- New activity (pdf view) is accessed
- Using putExtras - getExtras for variable passing, is working
Some code (from main activity.java):
#Override
public void onClick(View v) {
String scroll_page = new String("CommonVehicleCodeViolations.pdf");
Intent intent = new Intent(this, scroll_view.class);
intent.putExtra("extra_scroll_page", scroll_page);
startActivity(intent);
}
The diagram title is hard coded for testing purposes. Now, some code from the new activity (pdf view) 'scroll_view.java':
public class scroll_view extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll_view);
Bundle extras = getIntent().getExtras();
String scroll_page = null;
if (extras != null) {
scroll_page = extras.getString("extra_scroll_page");
}
int currentPage = 1;
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Bitmap bitmap = Bitmap.createBitmap(500,500, Bitmap.Config.ARGB_4444);
try {
File file = new File(getFilesDir(), scroll_page);
PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(file,ParcelFileDescriptor.MODE_READ_ONLY));
if(currentPage < 0) {
currentPage = 0;
} else if (currentPage > renderer.getPageCount()) {
currentPage = renderer.getPageCount() - 1;
}
renderer.openPage(currentPage).render(bitmap, new Rect(0, 0, 500, 500), new Matrix(),PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
} catch (IOException e) {
e.printStackTrace();
}
This was an attempt to use one of the many already posted answers which suggested using PdfRenderer. What I get from this example is the new activity (pdf view) blank screen. I am hoping that 2015 will bring new answers. Please help.
Why not try using an intent and let the system show you a list of compatible apps:
File file = new File(getFilesDir(), scroll_page);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
I'm new at Android apps and I'm working on a project started by a friend of mine. The code below is from a class that loads a view that has a small image with some text around it.
I want the image to appear fullscreen (on the standard Android image viewer) when I click on the thumbnail.
I tried several different solutions, and none of them worked.
This example throws the following exception:
E/AndroidRuntime(13768): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.app.mid/2130837533 typ=image/png }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_n1);
ImageView img = (ImageView) findViewById(imageResource);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("android.resource://com.app.mid/" + R.drawable.p_page_11_image_0001), "image/png");
startActivity(intent);
}
});
}
The images are inside the drawable folder (..\res\drawable-xhdpi). I'm using Eclipse ADT and I configured it to run on my Galaxy Nexus.
Again, I tried several solutions with no luck. Any thoughts?
Thanks
Try to use Intent.ACTION_VIEW instead of android.content.Intent.ACTION_VIEW
Intent i = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(yourUri, "image/png");
startActivity(intent);
The PDF content can be of online as well as offline mode, I need to show pdf in my own customized layout so, Intent can't be used. Any suggestion will be appreciated. thank you.
Yes we are able to show pdf content onLine with the help of google doc api Here i am given code for using it. for ON Line Mode
public class ReaderActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView=(WebView)this.findViewById(R.id.WebView01);
Intent intent = new Intent(Intent.ACTION_VIEW);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setPluginsEnabled(true);
webView.loadUrl("https://docs.google.com/viewer?url=http%3A%2F%2Fwww.eli.sdsu.edu%2Fcourses%2Ffall09%2Fcs696%2Fnotes%2FAndroid13Web.pdf");
//intent.setDataAndType(Uri.parse("https://docs.google.com/viewer?url=---------Your URL");
}}
for OFF Line Mode
File file = new File(mRealPath);
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, getString(R.string.application_type));
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(FirstTab.this,
getString(R.string.no_application_found),
Toast.LENGTH_SHORT).show();
}
Note-:In off line mode first you have download file form server to own local device in sd-card the get path of this document and put it on in the place of path variable then you get answer of your hole question.
In this code you should use your url in the place my url.
I hope this is help.
First of there is no support for pdf in Android so you need to open in some other app like adob or if you want to do it right way then need make the load lib like vudroid and apdfviewer .
apdfviewer is very good but there is no support how to compile source code, actually all lib work with c++ in backend so you need to install the ndk.
Vudroid is slow but you can compile easily.
I hope this will help you.
But
Some phones (like the Nexus One) come with a version of Quickoffice pre-installed so it may be as easy as sending the appropriate Intent once you've saved the file to the SD card.
public class OpenPdf extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.OpenPdfButton);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
File file = new File("/sdcard/example.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
}
});
}
}
I found that Internet connectivity mode :- through google doc we can open the pdf.
but in the Internet offline mode:- we need to use Intent and open the pdf file through any one of the pdf viewer application install in the device.
one things we can do in the offline mode is that, instead of opening the option of multiple pdf viewer reader in device and select one application to open pdf file we can open the pdf with the particular application.