forked from koying/SPMC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: [droid] proper BroadcastReceiver
- Loading branch information
Showing
6 changed files
with
141 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
xbmc/platform/android/activity/JNIXBMCBroadcastReceiver.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2018 Christian Browet | ||
* http://kodi.tv | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <algorithm> | ||
|
||
#include "JNIXBMCBroadcastReceiver.h" | ||
|
||
#include <androidjni/jutils-details.hpp> | ||
#include <androidjni/Intent.h> | ||
|
||
#include "XBMCApp.h" | ||
#include "CompileInfo.h" | ||
|
||
using namespace jni; | ||
|
||
static std::string s_className = std::string(CCompileInfo::GetClass()) + "/XBMCBroadcastReceiver"; | ||
|
||
CJNIXBMCBroadcastReceiver::CJNIXBMCBroadcastReceiver(CJNIBroadcastReceiver* receiver) | ||
: CJNIBase(s_className) | ||
, m_receiver(receiver) | ||
{ | ||
m_object = new_object(CXBMCApp::get()->getClassLoader().loadClass(GetDotClassName(GetClassName()))); | ||
m_object.setGlobal(); | ||
|
||
add_instance(m_object, this); | ||
} | ||
|
||
CJNIXBMCBroadcastReceiver::CJNIXBMCBroadcastReceiver(const CJNIXBMCBroadcastReceiver& other) | ||
: CJNIBase(other) | ||
{ | ||
add_instance(m_object, this); | ||
} | ||
|
||
CJNIXBMCBroadcastReceiver::~CJNIXBMCBroadcastReceiver() | ||
{ | ||
remove_instance(this); | ||
} | ||
|
||
void CJNIXBMCBroadcastReceiver::RegisterNatives(JNIEnv* env) | ||
{ | ||
jclass cClass = env->FindClass(s_className.c_str()); | ||
if(cClass) | ||
{ | ||
JNINativeMethod methods[] = | ||
{ | ||
{"_onReceive", "(Landroid/content/Intent;)V", (void*)&CJNIXBMCBroadcastReceiver::_onReceive}, | ||
}; | ||
|
||
env->RegisterNatives(cClass, methods, sizeof(methods)/sizeof(methods[0])); | ||
} | ||
} | ||
|
||
void CJNIXBMCBroadcastReceiver::_onReceive(JNIEnv *env, jobject thiz, jobject intent) | ||
{ | ||
(void)env; | ||
|
||
CJNIXBMCBroadcastReceiver *inst = find_instance(thiz); | ||
if (inst) | ||
inst->onReceive(CJNIIntent(jhobject::fromJNI(intent))); | ||
} | ||
|
||
void CJNIXBMCBroadcastReceiver::onReceive(CJNIIntent intent) | ||
{ | ||
if (m_receiver) | ||
m_receiver->onReceive(intent); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
/* | ||
* Copyright (C) 2018 Christian Browet | ||
* http://kodi.tv | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include <androidjni/JNIBase.h> | ||
|
||
#include <androidjni/BroadcastReceiver.h> | ||
|
||
namespace jni | ||
{ | ||
|
||
class CJNIXBMCBroadcastReceiver : public CJNIBroadcastReceiver, public CJNIInterfaceImplem<CJNIXBMCBroadcastReceiver> | ||
{ | ||
public: | ||
CJNIXBMCBroadcastReceiver(CJNIBroadcastReceiver* receiver); | ||
CJNIXBMCBroadcastReceiver(const CJNIXBMCBroadcastReceiver& other); | ||
CJNIXBMCBroadcastReceiver(const jni::jhobject &object) : CJNIBase(object) {} | ||
virtual ~CJNIXBMCBroadcastReceiver(); | ||
|
||
static void RegisterNatives(JNIEnv* env); | ||
|
||
public: | ||
void onReceive(CJNIIntent intent); | ||
|
||
protected: | ||
CJNIBroadcastReceiver* m_receiver; | ||
static void _onReceive(JNIEnv* env, jobject thiz, jobject intent); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters