How To Add Apk Share Button In SketchWare App


The example provided below shows how to Add Apk Share Button In SketchWare.
So Let's Follow.
add sketchware apk share feature
Share View


1. first of all Add A Button In View Areas.
Apk Share system

2. after that go to the Oncreate Activity and Copy Codes below and Paste Copy codes in oncreate activity.
share features
________________________________
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. Add A MoreBlocks Whose Name Is "Share" And Set Add Source Directly Component and Copy codes Below And Paste Add Source Directly Components.


(1) Add Source directly
_____________________________

}
______________________________

(2) Add Source directly
______________________________
private void shareApplication() { 
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()); 


}
______________________________

(3)  Add Source directly
______________________________

{
_______________________________


4. Go to the button And Set block Add Source directly and copy codes below and paste add source directly component.

______________________________

shareApplication();
___________________________

Post a Comment

Previous Post Next Post