آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

باز شدن Directory معین هنگام Tap بر روی Notification در Notification Bar

Hossein Kurd  11 سال پیش  11 سال پیش
+3 0

سلام دوستان

توی App می خوام فایل PDF یا DOC رو دانلود کنه و پروسه دانلود در Notification Bar نمایش داده بشه

به همین خاطر از DownloadManager استفاده کردم و به خاطر استفاده از اون minsdk رو به 10 ارتقا دادم(ایرانه دیگه ، به قول دوستم : هنوز IE6 استفاده می شه)

از اونجایی که در APIs 10 اتمام دانلود به صورت خودکار تشخص داده نمی شه مجبور شدم از Download Broadcast Receiver بنویسم و پس از اتمام دانلود ، دستی Notification بسازم :

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.i("Download" , "DownloadBroadcastReceiver >> Action : " + action);
        if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)){
            Log.i("Download" , "DownloadBroadcastReceiver >> Action Equals Download Complete");
            new BuildNotification().build(context);
        }

برای ساخت Notification از کد زیر استفاده کردم :

public void build(Context context){
        try{
            String path = ""+Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/";
            Log.i("Notification", "BuildNotification >> path : " + path);
            String title = "Title";
            String body = "Download Completed";
//            File file = new File(path);
            Uri uri = Uri.parse(path);
            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Notification notifyDetails = new Notification(R.drawable.notification_logo, title, System.currentTimeMillis());
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
//            intent.setDataAndType(uri, "resource/folder");
            intent.setDataAndType(Uri.parse("file:/" + path), "file/*");

            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent , 0);
            notifyDetails.setLatestEventInfo(context.getApplicationContext(), MainActivity.context.getString(R.string.app_name), body, contentIntent);
            mNotificationManager.notify(1, notifyDetails);
        }catch(Exception exception)
        {
            Log.e("Notification" , "Error : " + exception.getMessage());
        }
    }

شاهدان عینی می گن حدود 1000 بار کد رو تغییر دادم ، می خوام Directory عمومی Download واسه کاربر پس از Tap باز بشه !

 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .