native. js of DCloud calls the system to share the Android version code of the instance

  • 2021-10-15 11:40:12
  • OfStack

Native. js technology of DCloud, abbreviated as NJS, is a technology that escapes and maps the native object of mobile phone operating system to JS object, and writes native code in JS

Although Native. js is powerful and open, many web developers are difficult to complete independently because they are not familiar with the native API. Today, I would like to share with you the example code of Android version of how to call the system sharing function by using native. js


function share(shareTip,shareText){
 // Import Java Class object 
 var Context = plus.android.importClass("android.content.Intent");
 // Get the application master Activity
 var Main = plus.android.runtimeMainActivity();
 // Will class Context This behavior of (Action)ACTION_SEND , assign to shareIntent
 var shareIntent=new Context(Context.ACTION_SEND);
 //*** The following two ways of writing are 1 Like 
 //plus.android.invoke(shareIntent,"setType","text/plain");
 //plus.android.invoke(shareIntent,"putExtra",Context.EXTRA_TEXT,shareText);
 // Set the sharing type 
 shareIntent.setType("text/plain"); 
 // Set shared text 
 shareIntent.putExtra(Context.EXTRA_TEXT, shareText);
 //*** The above two ways of writing are 1 Like 
 // Specify the package name to share 
 //shareIntent.setPackage('com.tencent.mm',);
 Main.startActivity(Context.createChooser(shareIntent,shareTip));
}

The following is the native Android calling system sharing function code, which can be compared and understood by everyone


Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent,'send to...'));

Attached is a detailed introduction and explanation of Native of Dcloud. API supported by js

www.dcloud.io/docs/api/index.html

We will continue to share the common example code of Native. js of Dcloud for you. I hope you will pay attention to us


Related articles: