(۱۳۹۴/۱۱/۰۱, ۰۲:۳۷ ب.ظ)hassan_dang3r نوشته: سلام دوستان خسته نباشید
میخواستم بدونم چجوری میشه باButton یا imageButton داخل برنامه لینک بدیم به یه برنامه دیگه مثلا تلگرام ....
بعد بخوایم مثلا با Button لینک دانلود یه فایلی رو بدیم که کاربر بتونه با اون فایل رو دانلود کنه و مسیری که خودمون میدیم ذخیره شه .
سوال بعدیمم لینک دادن به یک سایت که بتونیم لینک بدیم به یک سایت که مرورگر گوشی رو باز کنه .
ممنون میشم راهنمایی کنید
با سلام خدمت دوست عزیزم،
جواب سوال اول: اگه میخواید برنامه مورد نظرتون باز بشه توسط یک باتن به صورت زیر عمل کنید:
کد پیاچپی:
try{PackageManager packageManager=getPackageManager();
Intent intent=packageManager.getLaunchIntentForPackage("kelidestan.com");
if(null!=intent){startActivity(intent);
}
}
catch(ActivityNotFoundException e)
{
به جای kelidestan.com پکیج برنامه مورد نظرتون رو بنویسید.
جواب سوال دومتون :یک فایل دانلود بشه و توی یک پروگرس نشون بده و محل ذخیره رو انتخاب کنیم به صورت زیر عمل کنید:
کد پیاچپی:
public class DownloadService extends IntentService {
public static final int UPDATE_PROGRESS = 8344;
public DownloadService() {
super("DownloadService");
}
@Override
protected void onHandleIntent(Intent intent) {
String urlToDownload = intent.getStringExtra("url");
ResultReceiver receiver = (ResultReceiver) intent.getParcelableExtra("receiver");
try {
URL url = new URL(urlToDownload);
URLConnection connection = url.openConnection();
connection.connect();
// this will be useful so that you can show a typical 0-100% progress bar
int fileLength = connection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(connection.getInputStream());
OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk");
byte data[] = new byte[1024];
long total = 0;
int count;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
Bundle resultData = new Bundle();
resultData.putInt("progress" ,(int) (total * 100 / fileLength));
receiver.send(UPDATE_PROGRESS, resultData);
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
}
Bundle resultData = new Bundle();
resultData.putInt("progress" ,100);
receiver.send(UPDATE_PROGRESS, resultData);
}
}
جواب سوال سوم: لینک دادن به یک سایت یا یک فایل دانلودی به صورت زیر عمل کنید:
کد پیاچپی:
Intent browserIntent = newIntent(Intent.ACTION_VIEW, Uri.parse("kelidestan.com"));
startActivity(browserIntent);
به جای kelidestan.com ادرس لینک خودتون رو بزارید.
موفق و موید باشید.
***خطا و مشکلات در برنامه نویسی پایه موفقیت است و به وسیله ی آن می توان به موفقیت رسید.***