mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-29 14:34:32 +00:00
Added tool for open Play Store with app details and apps list
This commit is contained in:
parent
b36fe5dcc4
commit
33b93468c1
@ -50,6 +50,7 @@
|
||||
<li><a href="#Screen">Screen</a></li>
|
||||
<li><a href="#BatteryState">BatteryState</a></li>
|
||||
<li><a href="#SignalStrength">SignalStrength</a></li>
|
||||
<li><a href="#PlayStore">PlayStore</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
@ -75,7 +76,8 @@
|
||||
QTAT_IMAGES \
|
||||
QTAT_NOTIFICATION \
|
||||
QTAT_ADMOB_BANNER \
|
||||
QTAT_ADMOB_INTERSTITIAL</pre>
|
||||
QTAT_ADMOB_INTERSTITIAL \
|
||||
QTAT_PLAY_STORE</pre>
|
||||
</li>
|
||||
<li>In the <i>main()</i> body insert the call for initialize the library<br />
|
||||
<pre class="prettyprint">QtAndroidTools::InitializeQmlTools();</pre>
|
||||
@ -430,6 +432,17 @@ QtAndroidSignalStrength.signalLevel</pre>
|
||||
<p><b>PLEASE NOTE:</b> the report the the signal strength change doesn't arrive immediately but, instead, require some seconds to be updated after the change. Don't worry if you don't see an immediate update, just wait a little.</p>
|
||||
<img src="images/signalstrength1.png">
|
||||
</div>
|
||||
<div class="section-txt" id="PlayStore">
|
||||
<h3>PlayStore</h3>
|
||||
<p>This tool allow to open Play Store app details and developer apps list.</p>
|
||||
<pre class="prettyprint">import QtAndroidTools 1.0
|
||||
|
||||
QtAndroidPlayStore.openAppDetails(packageName)
|
||||
QtAndroidPlayStore.openDeveloperAppList(developerName)</pre>
|
||||
<p>The first call open the Play Store app with the details page of the package name app provided (in the format "com.company.appname").</p>
|
||||
<p>NOTE: it's possible to call this method without any param, in this case the tool will use the app package name automatically.</p>
|
||||
<p>The second call will open Play Store listing all the apps connected with the developer name passed in the param.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
80
QtAndroidTools/QAndroidPlayStore.cpp
Normal file
80
QtAndroidTools/QAndroidPlayStore.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Fabio Falsini <falsinsoft@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include "QAndroidPlayStore.h"
|
||||
|
||||
QAndroidPlayStore *QAndroidPlayStore::m_pInstance = nullptr;
|
||||
|
||||
QAndroidPlayStore::QAndroidPlayStore() : m_JavaPlayStore("com/falsinsoft/qtandroidtools/AndroidPlayStore",
|
||||
"(Landroid/app/Activity;)V",
|
||||
QtAndroid::androidActivity().object<jobject>())
|
||||
{
|
||||
m_pInstance = this;
|
||||
}
|
||||
|
||||
QObject* QAndroidPlayStore::qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||
{
|
||||
Q_UNUSED(engine);
|
||||
Q_UNUSED(scriptEngine);
|
||||
|
||||
return new QAndroidPlayStore();
|
||||
}
|
||||
|
||||
QAndroidPlayStore* QAndroidPlayStore::instance()
|
||||
{
|
||||
return m_pInstance;
|
||||
}
|
||||
|
||||
void QAndroidPlayStore::openAppDetails(const QString &packageName)
|
||||
{
|
||||
QString DetailsParam("details?id=");
|
||||
|
||||
if(packageName.isEmpty())
|
||||
{
|
||||
const QAndroidJniObject Activity = QtAndroid::androidActivity();
|
||||
DetailsParam += Activity.callObjectMethod("getPackageName", "()Ljava/lang/String;").toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
DetailsParam += packageName;
|
||||
}
|
||||
|
||||
if(m_JavaPlayStore.isValid())
|
||||
{
|
||||
m_JavaPlayStore.callMethod<void>("open",
|
||||
"(Ljava/lang/String;)V",
|
||||
QAndroidJniObject::fromString(DetailsParam).object<jstring>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidPlayStore::openDeveloperAppList(const QString &developerName)
|
||||
{
|
||||
if(m_JavaPlayStore.isValid())
|
||||
{
|
||||
m_JavaPlayStore.callMethod<void>("open",
|
||||
"(Ljava/lang/String;)V",
|
||||
QAndroidJniObject::fromString("developer?id=" + developerName).object<jstring>()
|
||||
);
|
||||
}
|
||||
}
|
46
QtAndroidTools/QAndroidPlayStore.h
Normal file
46
QtAndroidTools/QAndroidPlayStore.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Fabio Falsini <falsinsoft@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtAndroidExtras>
|
||||
#include <QQmlEngine>
|
||||
|
||||
class QAndroidPlayStore : public QObject
|
||||
{
|
||||
Q_DISABLE_COPY(QAndroidPlayStore)
|
||||
Q_OBJECT
|
||||
|
||||
QAndroidPlayStore();
|
||||
|
||||
public:
|
||||
static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);
|
||||
static QAndroidPlayStore* instance();
|
||||
|
||||
Q_INVOKABLE void openAppDetails(const QString &packageName = QString());
|
||||
Q_INVOKABLE void openDeveloperAppList(const QString &developerName);
|
||||
|
||||
private:
|
||||
const QAndroidJniObject m_JavaPlayStore;
|
||||
static QAndroidPlayStore *m_pInstance;
|
||||
};
|
@ -52,6 +52,9 @@
|
||||
#ifdef QTAT_ADMOB_INTERSTITIAL
|
||||
#include "QAndroidAdMobInterstitial.h"
|
||||
#endif
|
||||
#ifdef QTAT_PLAY_STORE
|
||||
#include "QAndroidPlayStore.h"
|
||||
#endif
|
||||
#include "QtAndroidTools.h"
|
||||
|
||||
QtAndroidTools::QtAndroidTools()
|
||||
@ -90,4 +93,7 @@ void QtAndroidTools::InitializeQmlTools()
|
||||
#ifdef QTAT_ADMOB_INTERSTITIAL
|
||||
qmlRegisterType<QAndroidAdMobInterstitial>("QtAndroidTools", 1, 0, "QtAndroidAdMobInterstitial");
|
||||
#endif
|
||||
#ifdef QTAT_PLAY_STORE
|
||||
qmlRegisterSingletonType<QAndroidImages>("QtAndroidTools", 1, 0, "QtAndroidPlayStore", &QAndroidPlayStore::qmlInstance);
|
||||
#endif
|
||||
}
|
||||
|
@ -99,4 +99,12 @@ contains(DEFINES, QTAT_NOTIFICATION) {
|
||||
LIBS += -ljnigraphics
|
||||
}
|
||||
|
||||
contains(DEFINES, QTAT_PLAY_STORE) {
|
||||
HEADERS += $$PWD/QAndroidPlayStore.h
|
||||
SOURCES += $$PWD/QAndroidPlayStore.cpp
|
||||
OTHER_FILES += $$PWD/src/com/falsinsoft/qtandroidtools/AndroidPlayStore.java
|
||||
copy_play_store.commands = $(COPY_FILE) $$shell_path($$PWD/src/com/falsinsoft/qtandroidtools/AndroidPlayStore.java) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/src/com/falsinsoft/qtandroidtools/)
|
||||
PRE_TARGETDEPS += copy_play_store
|
||||
QMAKE_EXTRA_TARGETS += copy_play_store
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 Fabio Falsini <falsinsoft@gmail.com>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.falsinsoft.qtandroidtools;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.ComponentName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AndroidPlayStore
|
||||
{
|
||||
private final Activity mActivityInstance;
|
||||
|
||||
public AndroidPlayStore(Activity ActivityInstance)
|
||||
{
|
||||
mActivityInstance = ActivityInstance;
|
||||
}
|
||||
|
||||
public void open(String params)
|
||||
{
|
||||
Intent PlayStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://" + params));
|
||||
final List<ResolveInfo> AppInfoList = mActivityInstance.getPackageManager().queryIntentActivities(PlayStoreIntent, 0);
|
||||
boolean PlayStoreFound = false;
|
||||
|
||||
for(ResolveInfo AppInfo: AppInfoList)
|
||||
{
|
||||
if(AppInfo.activityInfo.applicationInfo.packageName.equals("com.android.vending"))
|
||||
{
|
||||
PlayStoreFound = true;
|
||||
|
||||
PlayStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
PlayStoreIntent.setComponent(new ComponentName(AppInfo.activityInfo.applicationInfo.packageName, AppInfo.activityInfo.name));
|
||||
|
||||
mActivityInstance.startActivity(PlayStoreIntent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(PlayStoreFound == false)
|
||||
{
|
||||
Intent WebPlayStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/" + params));
|
||||
mActivityInstance.startActivity(WebPlayStoreIntent);
|
||||
}
|
||||
}
|
||||
}
|
@ -93,6 +93,7 @@ ApplicationWindow {
|
||||
ListElement { title: "Notification"; source: "qrc:/tools/AndroidNotification.qml" }
|
||||
ListElement { title: "AdMobBanner"; source: "qrc:/tools/AndroidAdMobBanner.qml" }
|
||||
ListElement { title: "AdMobInterstitial"; source: "qrc:/tools/AndroidAdMobInterstitial.qml" }
|
||||
ListElement { title: "PlayStore"; source: "qrc:/tools/AndroidPlayStore.qml" }
|
||||
}
|
||||
|
||||
ScrollIndicator.vertical: ScrollIndicator { }
|
||||
|
@ -31,7 +31,8 @@ DEFINES += \
|
||||
QTAT_IMAGES \
|
||||
QTAT_NOTIFICATION \
|
||||
QTAT_ADMOB_BANNER \
|
||||
QTAT_ADMOB_INTERSTITIAL
|
||||
QTAT_ADMOB_INTERSTITIAL \
|
||||
QTAT_PLAY_STORE
|
||||
include(../QtAndroidTools/QtAndroidTools.pri)
|
||||
}
|
||||
|
||||
|
@ -12,5 +12,6 @@
|
||||
<file>tools/AndroidImages.qml</file>
|
||||
<file>tools/AndroidScreen.qml</file>
|
||||
<file>tools/AndroidNotification.qml</file>
|
||||
<file>tools/AndroidPlayStore.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
39
QtAndroidToolsDemo/tools/AndroidPlayStore.qml
Normal file
39
QtAndroidToolsDemo/tools/AndroidPlayStore.qml
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Dialogs 1.3
|
||||
import QtAndroidTools 1.0
|
||||
|
||||
Page {
|
||||
id: page
|
||||
padding: 0
|
||||
|
||||
Column {
|
||||
width: parent.wdith
|
||||
height: parent.height * 0.8
|
||||
anchors.centerIn: parent
|
||||
spacing: 20
|
||||
|
||||
TextEdit {
|
||||
id: packageName
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "com.falsinsoft.recomposephotopuzzle"
|
||||
}
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "openAppDetails"
|
||||
onClicked: QtAndroidPlayStore.openAppDetails(packageName.text)
|
||||
}
|
||||
|
||||
TextEdit {
|
||||
id: developerName
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "FalsinSoft"
|
||||
}
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "openDeveloperAppList"
|
||||
onClicked: QtAndroidPlayStore.openDeveloperAppList(developerName.text)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user