Apk share

 



T

This page will show how to share apk in sketchware project.

T



1.Add an button button1 in your sketchware project.



2.In on create activity add an add source directly block 
1.

In add source directly block paste the code as shown below:


StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); if(Build.VERSION.SDK_INT>=24){ try{ java.lang.reflect.Method m = StrictMode.class.getMethod( "disableDeathOnFileUriExposure"); m.invoke(null); } catch(Exception e){ showMessage(e.toString()); } }

3.In more block area create an block share






In moreblock add an add source directly block,in add source directly block add the code shown below

InIn


android.content.pm.ApplicationInfo app = getApplicationContext().getApplicationInfo(); String filePath = app.sourceDir; Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("*/*"); java.io.File originalApk = new java.io.File(filePath); try { java.io.File tempFile = new java.io.File(getExternalCacheDir() + "/ExtractedApk"); if (!tempFile.isDirectory()) if (!tempFile.mkdirs()) return; tempFile = new java.io.File(tempFile.getPath() + "/" + "export.apk"); if (!tempFile.exists()) { try{ if (!tempFile.createNewFile()) { return; } } catch (java.io.IOException e){} } java.io.InputStream in = new java.io.FileInputStream (originalApk); java.io.OutputStream out = new java.io.FileOutputStream(tempFile); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile)); startActivity(Intent.createChooser(intent, "Share app via")); } catch (java.io.IOException e) { showMessage(e.toString());


4.In onClick event of button1 add moreblock share application as shown below





5.Save and run the project.

45

Comments

Popular posts from this blog

Download any file from url

Save any image in phone storage