Click here to Skip to main content
15,914,165 members

Comments by Member 11796538 (Top 2 by date)

Member 11796538 29-Jun-15 6:52am View    
this is my code

String s = mdataarrayforNotes.getM_FilePath();

final String fileName = s.substring(s.lastIndexOf('/') + 1);
File filesname=new File(fileName);
Log.d("",fileName.toString());


Boolean isSDPresent = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);

if (isSDPresent)
{
// yes SD-card is present
final File mydir = new File("/sdcard/WaliaApp/");

Log.d("Error create path", mydir.toString());
if (!mydir.exists())
{
mydir.mkdirs();
}
else
{
Log.d("error", "dir. already exists");
}

// File myfile = new File("/sdcard/"+fileName);
// myfile.setReadable(true);
// myfile.setWritable(true);
Log.d("error check", filesname.toString());

if (filesname.exists())
{
Log.d("error", "File Avaliable.");
}
else
{
Uri source = Uri.parse(s);
DownloadManager.Request request = new DownloadManager.Request(source);
request.setDescription("Now Downloading FIle");
request.setTitle(fileName);
request.setMimeType("application/pdf");
request.setDestinationInExternalPublicDir(String.valueOf(mydir), fileName);
String sumit= String.valueOf(request.setDestinationInExternalPublicDir(String.valueOf(mydir), fileName));


Log.d("Erorr save path", sumit);
Log.d("Erorr save path", mydir.toString());
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Notes.this.DOWNLOAD_SERVICE);

manager.enqueue(request);

BroadcastReceiver onComplete=new BroadcastReceiver()
{
public void onReceive(Context ctxt, Intent intent)
{


File f = new File("/sdcard/WaliaApp/"+fileName);
//.getAbsolutePath()
// f.setReadable(true);
Log.d("Error open path", f.toString());

// Uri path = Uri.fromFile(f);


PackageManager packageManager = getPackageManager();
Intent testIntent = new Intent(Intent.ACTION_VIEW);
testIntent.setType("application/pdf");
List list = packageManager.queryIntentActivities(testIntent, PackageManager.MATCH_DEFAULT_ONLY);

try
{

if (list.size() > 0 && f.isFile()) {
Intent intent1 = new Intent();
Member 11796538 29-Jun-15 6:06am View    
i am able to download file but not able to view it,no erros after compilation