public void CameraOnClick(){
using (AndroidJavaClass javaClass = new AndroidJavaClass ("com.d3d.viewer.NativePlugin")) {
using (AndroidJavaObject currentActivity = javaClass.CallStatic<AndroidJavaObject> ("instance")) {
Debug.Log ("Start Camera@@@@@@@@@@@@");
//javaClass.CallStatic ("showCamera");
currentActivity.Call("showCamera");
}
}
}
public void getimageUrl1(string ImageUrl){
imageurl1 = ImageUrl;
Debug.Log ("ImageUrl11111111111111111111"+ImageUrl);
}
Android来源
public class NativePlugin extends UnityPlayerActivity {
final Activity b = m_instance;
final Activity a = UnityPlayer.currentActivity;
private static NativePlugin m_instance;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
UnityPlayer.UnitySendMessage("PlusPopupManager","getimageUrl1","22222"); //don't activate
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 1);
}
public static NativePlugin instance()
{
if(m_instance == null)
{
m_instance = new NativePlugin();
}
return m_instance;
}
public void showCamera () // Connect Camera
{
UnityPlayer.UnitySendMessage("PlusPopupManager","getimageUrl1","111111"); //activate
a.runOnUiThread(new Runnable()
{
public void run() {
Intent intent = new Intent(a, NativePlugin.class);
a.startActivity(intent);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
UnityPlayer.UnitySendMessage("PlusPopupManager","getimageUrl1","333333");//don't activate
}
}
manifast.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.d3d.viewer">
<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">
<activity android:name="com.d3d.viewer.NativePlugin" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
</manifest>
我制作ARR android插件。并导入Unity3d。
当我调用'showCamera'时,会激活'UnityPlayer.UnitySendMessage'。 但是当我调用intent(NativePlugin)函数时不要激活。为什么不在Android活动上调用'UnityPlayer.UnitySendMessage'功能。