Advertisement
Guest User

sendSMS qt for android 5.2.0 cpp

a guest
Jan 10th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.45 KB | None | 0 0
  1. W/dalvikvm(10875): threadid=11: thread exiting with uncaught exception (group=0x4156e930)
  2. E/AndroidRuntime(10875): FATAL EXCEPTION: Thread-936
  3. E/AndroidRuntime(10875): java.lang.SecurityException: Sending SMS message: uid 10084 does not have android.permission.SEND_SMS.
  4. E/AndroidRuntime(10875):    at android.os.Parcel.readException(Parcel.java:1425)
  5. E/AndroidRuntime(10875):    at android.os.Parcel.readException(Parcel.java:1379)
  6. E/AndroidRuntime(10875):    at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:434)
  7. E/AndroidRuntime(10875):    at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
  8. E/AndroidRuntime(10875):    at dalvik.system.NativeStart.run(Native Method)
  9. I/AndroidRuntime(10875): VM exiting with result code 0, cleanup skipped.
  10.  
  11. My AndroidManifest.xml:
  12. <?xml version='1.0' encoding='utf-8'?>
  13. <manifest package="org.kde.necessitas.example.snowloadcount" android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1">
  14.     <application android:label="@string/app_name" android:name="org.kde.necessitas.origo.QtApplication" android:icon="@drawable/icon">
  15.         <activity android:label="@string/app_name" android:name="org.kde.necessitas.origo.QtActivity" android:configChanges="orientation|locale|fontScale|keyboard|keyboardHidden">
  16.             <intent-filter>
  17.                 <action android:name="android.intent.action.MAIN"/>
  18.                 <category android:name="android.intent.category.LAUNCHER"/>
  19.             </intent-filter>
  20.             <meta-data android:resource="@array/qt_libs" android:name="android.app.qt_libs_resource_id"/>
  21.             <meta-data android:resource="@array/bundled_libs" android:name="android.app.bundled_libs_resource_id"/>
  22.             <meta-data android:value="snowloadcount" android:name="android.app.lib_name"/>
  23.             <!--  Messages maps -->
  24.             <meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
  25.             <meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
  26.             <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
  27.             <!--  Messages maps -->
  28.             <!-- Splash screen -->
  29.             <meta-data android:resource="@layout/splash" android:name="android.app.splash_screen"/>
  30.             <!-- Splash screen -->
  31.         </activity>
  32.     </application>
  33.     <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/>
  34.     <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="17"/>
  35.     <uses-permission android:name="android.permission.BROADCAST_SMS"/>
  36.     <uses-permission android:name="android.permission.INTERNET"/>
  37.     <uses-permission android:name="android.permission.READ_SMS"/>
  38.     <uses-permission android:name="android.permission.SEND_SMS"/>
  39.     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  40. </manifest>
  41.  
  42. void TruckTypeTotalsPage::sendSMS(QString phoneNumber, QString message)
  43. {
  44.     QAndroidJniEnvironment env;
  45.  
  46.     //This is the original NON-JNI android java code
  47.     //SmsManager smsManager = SmsManager.getDefault();
  48.     //smsManager.sendTextMessage("Phone Number", null, "Message", null, null);
  49.     //in background (Not showing message composer)
  50.  
  51.     //The following attempts to do the same as the above,
  52.     //but using C++/qt for android's JNI classes/apis.
  53.     //HATS OFF to QT FOR ANDROID!
  54.  
  55.     QAndroidJniObject mySmsManager = QAndroidJniObject::callStaticObjectMethod("android/telephony/SmsManager", "getDefault", "()Landroid/telephony/SmsManager;" );
  56.     QAndroidJniObject myPhoneNumber = QAndroidJniObject::fromString(phoneNumber);
  57.     QAndroidJniObject myTextMessage = QAndroidJniObject::fromString(message);
  58.     QAndroidJniObject scAddress = NULL;
  59.     QAndroidJniObject sentIntent = NULL;
  60.     QAndroidJniObject deliveryIntent = NULL;
  61.     mySmsManager.callMethod<void>("sendTextMessage", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Landroid/app/PendingIntent;Landroid/app/PendingIntent;)V" , myPhoneNumber.object<jstring>(), scAddress.object<jstring>(), myTextMessage.object<jstring>(), NULL, NULL );
  62. }
  63.  
  64. This sendSMS() service gets called from a QWizardPage::validate() callback from a finish button that simply sends a stats report totalling the number of trucks that dumped their snow at a snow disposal site and then closes the application.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement