URL Scheme

Android URL Scheme

MainActivity中初始化加入代码,接受网页传递过来的URL Scheme,并解析URL

 

protected void onCreate(Bundle savedInstanceState) {
     
super.onCreate(savedInstanceState);

      Intent intent = getIntent();
        String scheme =intent.getScheme();
        String dataString =intent.getDataString();
        Uri uri = intent.getData();
        Log.e(
"unity","scheme "+ scheme);
       
if (uri != null){
            String url = uri.toString();
            String scheme1 =uri.getScheme();
            String host = uri.getHost();
           
int port = uri.getPort();
            String path = uri.getPath();
// 访问路劲
//            ListpathSegments = uri.getPathSegments();
           
String query =uri.getQuery();// Query部分
           
String goodsId = uri.getQueryParameter("goodsId"); //获取指定参数值
           
Log.e("unity", "url: " + uri);
            Log.e(
"unity", "scheme1 :" + scheme1);
            Log.e(
"unity", "host: "+ host);
            Log.e(
"unity", "host: "+ port);
            Log.e(
"unity", "path: "+ path);
            Log.e(
"unity", "query:" + query);
            Log.e(
"unity", "goodsId:" + goodsId);
        }
   }

URL Scheme_第1张图片

AndroidMainFest.xml中配置一下文件

           

               

               

               

           

                           

                                    

               

                                      

               

                                      

               

                                  

           

           

            

       

URL Scheme_第2张图片

Unity 中代码调用 

local url = "http://friend.php?"—自己做的跳转链接界面,为了防止玩家直接看URLscheme

local url1 = "http://line.me/R/msg/text/?啊哈哈哈哈哈哈「下载链接urlscheme」「"

local url2 = url.."pid="..uuid..""

Application.OpenURL(url1..url2)

ios URL Scheme

设置URLscheme

URL Scheme_第3张图片

通过第三方APP打开分享的链接,进入游戏时自动调用这个接口,接口写在appdelegate.m(网上说的,我是没有appdelegate.m,就写在了UnityAPPController.mm)里面

- (BOOL)application:(UIApplication*)applicationopenURL:(NSURL*)url sourceApplication:(NSString*)sourceApplicationannotation:(id)annotation

{

    NSLog(@"sourceApplication: %@",sourceApplication);

    NSLog(@"URL scheme:%@", [urlscheme]);//设置的scheme

    NSLog(@"URL query: %@", [urlquery]);//获取到的URLscheme参数

//    ToGameEvent(43, [url scheme]);//将参数发送到unity,进行下一步处理

         return YES;

}

 

最后的URLscheme  symphony://

 

 

 

由于个人的项目中,UnityAPPController.mm是自动生成的,无法在其中编写代码,就在别处添加调用

UnityAppController.WriteBelow("NSMutableArray*values   = [NSMutableArrayarrayWithCapacity:3];", "    //好友招待传递过来的参数\n    NSLog(@\"URLscheme:%@\", [url scheme]);\n   NSLog(@\"URL query: %@\", [url query]);\n    NSString *param = [NSStringstringWithFormat:@\"%d#data=%@\",43,[url query]];\n    调用和SDK交互的接口,将参数传到unity;

 


你可能感兴趣的:(Android,IOS,unity3d)