Caused by: java.lang.SecurityException when use content resolver in android - android

I am reading android messages, calendars data etc. using content resolver. i added permission into manifest file. and also implemented runtime permission for reading/writing SMS & calendar. still i am getting below issue on some devices which are running in android 7.0 or higher.
Caused by: java.lang.SecurityException:
at android.os.Parcel.readException (Parcel.java:1693)
at android.os.Parcel.readException (Parcel.java:1646)
at android.app.ActivityManagerProxy.getContentProvider (ActivityManagerNative.java:4912)
at android.app.ActivityThread.acquireProvider (ActivityThread.java:6043)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider (ContextImpl.java:2474)
at android.content.ContentResolver.acquireUnstableProvider (ContentResolver.java:1521)
at android.content.ContentResolver.query (ContentResolver.java:520)
at android.content.ContentResolver.query (ContentResolver.java:478)
at com.allbackup.ui.activity.MsgsActivity.c (MsgsActivity.java:301)
at com.allbackup.ui.activity.MsgsActivity$c.a (MsgsActivity.java:201)
at com.allbackup.ui.activity.MsgsActivity$c.doInBackground (MsgsActivity.java:186)
above is the stacktrace of error while reading SMS. and below is the code for that:
Uri message = Uri.parse("content://sms/");
ContentResolver cr = getContentResolver();
Cursor c = cr.query(message, null, null, null, null);
//startManagingCursor(c);
int totalSMS = c.getCount();
if (c.moveToFirst()) {
if(c.getString(c.getColumnIndex("address")) != null){
add = c.getString(c.getColumnIndexOrThrow("address")).replaceAll("[\\s\\-()]", "");
map.put("address", c.getString(c.getColumnIndexOrThrow("address")).replaceAll("[\\s\\-()]", ""));
}else{
map.put("address", "");
}
if(!add.isEmpty()){
Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(add));
Cursor cno = getContentResolver().query(lookupUri, new String[]{ContactsContract.Data.DISPLAY_NAME_PRIMARY, ContactsContract.Data.PHOTO_THUMBNAIL_URI},null,null,null);
if(cno.getCount()>0){
try {
cno.moveToFirst();
map.put("name", cno.getString(0));
map.put("photo", cno.getString(1));
} catch (Exception e) {
// TODO: handle exception
}finally{
// cno.close();
}
}else{
map.put("name", "");
map.put("photo", "");
}
if(cno!=null)
cno.close();
}
}
I am getting error on below line:
Cursor cno = getContentResolver().query(lookupUri, new String[]{ContactsContract.Data.DISPLAY_NAME_PRIMARY, ContactsContract.Data.PHOTO_THUMBNAIL_URI},null,null,null);
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.allbackup">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".ui.activity.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/FullScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
</activity>
</application>
</manifest>

For all the dangerous permissions you need to request permission at runtime. Please refer this link

Before accessing the content using content provider you have to check the permission all the time. if not granted , then you have to request the permission on run-time and then try to fetch message.
if(ContextCompat.checkSelfPermission(getBaseContext(), "android.permission.READ_SMS") == PackageManager.PERMISSION_GRANTED) {
read your contacts here
}
For more information please refer to this site : https://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en

Related

Xamarin Android INSTALL_PARSE_FAILED_MANIFEST_MALFORMED

I'm recieving the above error when deploying my Xamarin Android application using Visual Studio in debug mode, the compile process completes fine but I can't deploy.
The app runs fine in Android 8.1.0 but not in any other lower version.
Error:
>Project "Empresa1.SMPay.Target.Droid.csproj" (Install target(s)):
>C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\zipalign.exe 4 "E:\HenkoTI\Empresa1\SMPay\src\mpay\app\Empresa1.SMPay.Target.Droid\obj\Debug\android\bin\br.com.henkoti.empresaum.smpay.apk" "bin\Debug\\br.com.henkoti.empresaum.smpay-Signed.apk"
>C:\Program Files (x86)\Android\android-sdk\build-tools\28.0.0-rc1\apksigner.BAT sign --ks "C:\Users\rodri\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 18 --max-sdk-version 27 bin\Debug\br.com.henkoti.empresaum.smpay-Signed.apk
>Unexpected install output: pkg: /data/local/tmp/br.com.henkoti.empresaum.smpay-Signed.apk
>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
>
> at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
> at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
> at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
> at System.Threading.Tasks.Task.Execute()
>Done building project "Empresa1.SMPay.Target.Droid.csproj".
>Build succeeded.
>Unexpected install output: pkg: /data/local/tmp/br.com.henkoti.empresaum.smpay-Signed.apk
>Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
>
> at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName)
> at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass94_0.<InstallPackage>b__0(Task`1 t)
> at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
> at System.Threading.Tasks.Task.Execute()
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.henkoti.empresaum.smpay" android:installLocation="auto" android:versionName="20181108.0" android:versionCode="4">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
<application android:icon="#drawable/ic_launcher" android:theme="#style/MainTheme" android:label="SIGO" android:allowBackup="true" android:fullBackupContent="#xml/my_backup_rules">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
</provider>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id" />
</application>
</manifest>
Compiled AndroidManifest - Obj Folder
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="br.com.henkoti.empresaum.smpay" android:installLocation="auto" android:versionName="20181108.0" android:versionCode="4">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BIND_NFC_SERVICE" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.location.network" />
<application android:icon="#drawable/ic_launcher" android:theme="#style/MainTheme" android:label="SIGO" android:allowBackup="true" android:fullBackupContent="#xml/my_backup_rules" android:name="md5eaa617bc1882abd453813d82db97fb16.MainApplication" android:debuggable="true">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="br.com.henkoti.empresaum.smpay.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="#xml/file_paths" />
</provider>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/facebook_app_id" />
<service android:enabled="true" android:exported="true" android:name="Empresa1.SMPay.HCECardService" android:permission="android.permission.BIND_NFC_SERVICE">
<meta-data android:name="android.nfc.cardemulation.host_apdu_service" android:resource="#xml/aid_list" />
<intent-filter>
<action android:name="android.nfc.cardemulation.action.HOST_APDU_SERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<activity android:configChanges="orientation|screenSize" android:launchMode="standard" android:screenOrientation="portrait" android:theme="#style/MainTheme" android:name="md5eaa617bc1882abd453813d82db97fb16.MainActivity" />
<activity android:icon="#drawable/ic_launcher" android:label="SIGO" android:noHistory="true" android:screenOrientation="portrait" android:theme="#style/SplashTheme" android:name="md5eaa617bc1882abd453813d82db97fb16.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:enabled="true" android:label="Connectivity Plugin Broadcast Receiver" android:name="md592d74be4bac08a7af63848ae15d2f86e.ConnectivityChangeBroadcastReceiver" />
<activity android:configChanges="orientation|screenSize" android:name="md5cf4be63b82b35b5ba951617c70f88a94.FilePickerActivity" />
<activity android:configChanges="orientation|screenSize" android:name="md591f613f6733d8b6e91e929a922515c0e.MediaPickerActivity" />
<receiver android:enabled="true" android:exported="false" android:name="md5b60ffeb829f638581ab2bb9b1a7f4f3f.PowerSaveModeBroadcastReceiver" />
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="br.com.henkoti.empresaum.smpay.mono.MonoRuntimeProvider.__mono_init__" />
<!--suppress ExportedReceiver-->
<receiver android:name="mono.android.Seppuku">
<intent-filter>
<action android:name="mono.android.intent.action.SEPPUKU" />
<category android:name="mono.android.intent.category.SEPPUKU.br.com.henkoti.empresaum.smpay" />
</intent-filter>
</receiver>
<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="#style/com_facebook_activity_theme" />
<activity android:name="com.facebook.CustomTabMainActivity" />
<!--
The initialization ContentProvider will call FacebookSdk.sdkInitialize automatically
with the application context. This config is merged in with the host app's manifest,
but there can only be one provider with the same authority activated at any given
point; so if the end user has two or more different apps that use Facebook SDK, only the
first one will be able to use the provider. To work around this problem, we use the
following placeholder in the authority to identify each host application as if it was
a completely different provider.
-->
<provider android:name="com.facebook.internal.FacebookInitProvider" android:authorities="br.com.henkoti.empresaum.smpay.FacebookInitProvider" android:exported="false" />
<activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar" android:excludeFromRecents="true" android:exported="false" />
<!--Service handling Google Sign-In user revocation. For apps that do not integrate with
Google Sign-In, this service will never be started.-->
<service android:name="com.google.android.gms.auth.api.signin.RevocationBoundService" android:exported="true" android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="#android:style/Theme.Translucent.NoTitleBar" android:exported="false" />
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
</application>
</manifest>
SplashActivity
using Android.OS;
using Android.App;
using Android.Content.PM;
namespace Empresa1.SMPay.Target.Droid
{
[Activity(Label = "SIGO",
Icon = "#drawable/ic_launcher",
Theme = "#style/SplashTheme",
MainLauncher = true,
NoHistory = true,
ScreenOrientation = ScreenOrientation.Portrait)]
public class SplashActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.StartActivity(typeof(MainActivity));
}
}
}
MainActivity
using System.Net;
using Android.App;
using Android.OS;
using Android.Content;
using Android.Content.PM;
using Xamarin.Forms;
using Xamarin.Facebook;
using Plugin.Toasts;
using Plugin.Permissions;
using Acr.UserDialogs;
using Autofac;
using Empresa1.SMPay.Application;
using Empresa1.SMPay.Application.IoC;
using Empresa1.SMPay.Target.Droid.Services;
using Empresa1.SMPay.Infra.Platform.Services;
using Android.Gms.Auth.Api;
using InteractiveAlert;
using Xfx;
using FFImageLoading.Forms.Droid;
namespace Empresa1.SMPay.Target.Droid
{
[Activity(Theme = "#style/MainTheme",
LaunchMode = LaunchMode.Multiple,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation,
ScreenOrientation = ScreenOrientation.Portrait)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
// Facebook
FacebookSdk.SdkInitialize(this.ApplicationContext);
global::Xamarin.Forms.Forms.Init(this, bundle);
// Calendar
XamForms.Controls.Droid.Calendar.Init();
// SSL
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
// Permissions
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
// Toast
DependencyService.Register<ToastNotification>();
ToastNotification.Init(this);
// Dialogs
UserDialogs.Init(() => (Activity)Forms.Context);
InteractiveAlerts.Init(() => this);
// XfxControls
XfxControls.Init();
// FFImageLoading
CachedImageRenderer.Init(true);
LoadApplication(new Empresa1.SMPay.Application.App(new Setup(this.ApplicationContext, this, TelephonyService)));
}
protected override void OnStart()
{
base.OnStart();
}
protected override void OnResume()
{
base.OnResume();
}
protected override void OnPause()
{
base.OnPause();
}
protected override void OnStop()
{
base.OnStop();
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
//base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (App.FacebookSinging)
{
// facebook auth
var facebookService = IoCContainer.Container.Resolve<IFacebookService>();
if (facebookService != null)
{
(facebookService as DroidFacebookService)._callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
}
}
else if (App.GoogleSinging)
{
// google auth
if (requestCode == 1)
{
var result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
DroidGoogleService.Instance.OnAuthCompleted(result); // TODO
}
}
}
}
}
Anyone here knows, what do i need to do?
I took some screenshots to add here:
Finally I was able to solve the problem, the solution was to change the prefix name of the HCECardService to lowecase.
Before: Empresa1.SMPay.HCECardService
After: empresa1.smpay.HCECardService
[Service(Exported = true, Enabled = true, Permission = "android.permission.BIND_NFC_SERVICE", Name = "empresa1.smpay.HCECardService"), IntentFilter(new[] { "android.nfc.cardemulation.action.HOST_APDU_SERVICE" }, Categories = new[] { "android.intent.category.DEFAULT" }),
MetaData("android.nfc.cardemulation.host_apdu_service", Resource = "#xml/aid_list")]
public class HCECardService : HostApduService
{ ... }

Android:SQLite to csv export

I am unable to export the SQLite data in to csv file.i am unable to see any LOGCAT also. Necessary permissions are granted in Manifest file. could you check and sharp wit your expertise.
Also opencsv and other supporting files are loaded.
Manifest file. Attaching with Manifest file,Mainactivity data for your kind review,
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.bar.example.myapplication">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:roundIcon="#mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="#style/AppTheme">
<activity android:name=".CourseSearchActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ScanActivity" />
</application>
</manifest>
Mainactivity.
btnexport.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
SQLiteDatabase db = openOrCreateDatabase("OCC", MODE_PRIVATE, null);
File exportDir = new File(getExternalFilesDir(null), "");
if (!exportDir.exists()) {
exportDir.mkdirs();
}
File file = new File(exportDir, "coke.csv");
try {
file.createNewFile();
com.bar.example.myapplication.CSVWriter csvWrite = new com.bar.example.myapplication.CSVWriter(new FileWriter(file));
Cursor curCSV = db.rawQuery("SELECT * FROM DATAALL", null);
csvWrite.writeNext(curCSV.getColumnNames());
while (curCSV.moveToNext()) {
//Which column you want to export
String arrStr[] = {
curCSV.getString(curCSV.getColumnIndex("_id")),
curCSV.getString(curCSV.getColumnIndex("Material_Barcode")),
curCSV.getString(curCSV.getColumnIndex("Material_Number")),
curCSV.getString(curCSV.getColumnIndex("Material_Description")),
curCSV.getString(curCSV.getColumnIndex("Scanning_Date")),
curCSV.getString(curCSV.getColumnIndex("Production_Date")),
curCSV.getString(curCSV.getColumnIndex("Expiry_Ratio")),
curCSV.getString(curCSV.getColumnIndex("Product_Durablity")),
curCSV.getString(curCSV.getColumnIndex("Qty")),
};
csvWrite.writeNext(arrStr);
}
csvWrite.close();
curCSV.close();
Toast.makeText(getApplicationContext(), "Downloaded Successfully", Toast.LENGTH_SHORT).show();
} catch (Exception sqlEx) {
Log.e("ResultActivity", sqlEx.getMessage(), sqlEx);
}
}
});

Android : Merging/concatenating two audio files hangs up the application

I'm appending two audio file using mp4parser. Appending is done but it is very slow don't know what is the issue.
On this line debugger stuck for big audio files for example approx 30 minutes audio file.
Container out = new DefaultMp4Builder().build(result);
Here is code.
Movie[] inMovies = null;
inMovies = new Movie[]{
MovieCreator.build(fileOne),
MovieCreator.build(fileTwo)};
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies) {
for (Track t : m.getTracks()) {
if (t.getHandler().equals("soun")) {
audioTracks.add(t);
}
}
}
Movie result = new Movie();
if (audioTracks.size() > 0) {
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
Container out = new DefaultMp4Builder().build(result);
String fileName = getFilename();
FileChannel fc = new RandomAccessFile(String.format(fileName), "rw").getChannel();
out.writeContainer(fc);
fc.close();
Manifestfile
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ehrlite"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ehr_icon"
android:label="#string/app_name"
android:name="com.webservice.myApplication"
android:theme="#style/AppTheme" >
<activity
android:name="com.ehrlite.LoginActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ehrlite.MasterActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.ehrlite.MainActivity"
android:screenOrientation="portrait"
>
</activity>
<activity
android:name="com.ehrlite.PrevMemo"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.webviewcall.WebViewActivity"
android:screenOrientation="portrait">
</activity>`enter code here`
<activity
android:name="com.ehrlite.TranscribedActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustPan">
</activity>
</application>
</manifest>
Can anyone help me out to improve performance,
thanks in advance.
I found the solution for your answer.
I was faced issue previously.
You are using RandomAccessfile. You need to use FileOutputStream
Container out = new DefaultMp4Builder().build(result);
String outputFilePath = getfilename();
FileOutputStream fos = new FileOutputStream(new File(outputFilePath));
out.writeContainer(fos.getChannel());
fos.close();
Reference:
why are java RandomAccessFile so much slower than FileOutputStream?

Broadcast receiver not working properly, onReceive() doesn't get invoked. How should I fix it?

My onReceive() doesn't get invoked at all even when application receives sms message. It doesn't get invoked when the message arrives. Shouldn't it be working in background and only gets invoked when the SMS arrives?
It works fine on a seperate project but not when I'm integraing to my own app.
My Code:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
public class SmsBroadcastReciever extends BroadcastReceiver {
private static final String LOG_TAG = "SMSBroadRec";
public static final String SMS_BUNDLE = "pdus";
String SenderNo = "+92----------";
String SenderNo2 = "+92----------";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(LOG_TAG, "In onReceive()");
Bundle bundle = intent.getExtras();
String smsBody;
String address;
try {
if ( !bundle.isEmpty() ){
Log.d(LOG_TAG, "Sms received");
String verificationCode = null;
Object[] sms = (Object[]) bundle.get(SMS_BUNDLE);
for (Object sm : sms) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sm);
smsBody = smsMessage.getMessageBody();
address = smsMessage.getOriginatingAddress();
Log.d(LOG_TAG, address);
if (SenderNo.equals(address) || SenderNo2.equals(address)) {
verificationCode = getVerificationCode(smsBody);
Log.e(LOG_TAG, "OTP received: " + verificationCode);
break;
} else {
Log.d(LOG_TAG, "wrong sender");
break;
}
}
SharedPreferences prefs = context.getSharedPreferences(AppConfig.APP_SCRATCH, Context.MODE_PRIVATE);
SharedPreferences.Editor ed = prefs.edit();
ed.putString(AppConfig.APP_SCRATCH, verificationCode);
if (ed.commit()) {
Log.d(LOG_TAG, "commit succesful"); //added to the shared preferences
} else {
Log.d(LOG_TAG, "commit unsuccessful");
}
} else {
Log.d(LOG_TAG, "Intent must be empty!");
}
}
catch (Exception e){
e.printStackTrace();
}
}
private String getVerificationCode(String message) {
String code = null;
int index = message.indexOf(AppConfig.OTP_DELIMITER);
if (index != -1) {
int start = index + 2;
int length = 8;
code = message.substring(start, start + length);
return code;
}
return code;
}
}
This is the part of the manifest file and i have added permissions too which are READ_SMS, RECEIVE_SMS, WRITE_SMS.
manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ubroadkast.nayatel"
android:versionCode="4"
android:versionName="1.3">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="true" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<uses-permission
android:name="android.permission.INTERNET"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission
android:name="android.permission.RECORD_AUDIO"
android:required="true" />
<uses-permission
android:name="android.permission.CAMERA"
android:required="true" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.SEND_SMS"
android:required="true" />
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.CHANGE_WIFI_STATE"
android:required="true" />
<uses-permission
android:name="android.permission.READ_CONTACTS"
android:required="true" />
<uses-permission
android:name="android.permission.WRITE_CONTACTS"
android:required="true" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:required="true" />
<uses-permission android:name="android.permission.WRITE_SMS"
android:required="true"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"
android:required="true"/>
<uses-permission android:name="android.permission.READ_SMS"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Ubroadkast">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider912845522101212"
android:exported="true" />
<activity
android:name=".MainActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:screenOrientation="landscape" />
<activity
android:name=".Home"
android:label="#string/app_name"
android:screenOrientation="portrait" />
<activity
android:name=".Settings"
android:label="Settings"
android:screenOrientation="portrait" />
<activity
android:name=".UserStatus"
android:label="#string/title_activity_user_status" />
<activity
android:name=".login"
android:label="#string/app_name"
android:screenOrientation="portrait" />
<activity
android:name=".SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".facebook"
android:label="UBroadkast Facebook Sign In"
android:screenOrientation="portrait" />
<activity
android:name=".Terms"
android:label="Terms And Conditions"
android:screenOrientation="portrait" />
<activity
android:name=".Signup"
android:label="Sign Up"
android:screenOrientation="portrait" />
<activity
android:name=".rating"
android:label="Ubroadkast Feedback"
android:screenOrientation="portrait" />
<activity
android:name=".change_password"
android:label="Reset Password" />
<activity android:name=".HomeScreen" />
<activity android:name=".Videoview" />
<activity android:name=".URLExtractor" />
<receiver android:name=".SmsBroadcastReciever" android:enabled="true" android:exported="false">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECIEVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
change following line in manifest from
<action android:name="android.provider.Telephony.SMS_RECIEVED"/>
to
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
There's a spelling mistake of word "received".

Orientation issue in Hybrid Android Application

Kindly help me in this problem.. i am working in the hybrid android mobile application.. it works correctly but when i changed the orientation the application gets restarted.... both in portrait and landscape...
This is my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true"
android:resizeable="true"
android:anyDensity="true"
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:allowBackup="true"
android:icon="#drawable/icon_dropin"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name="com.cogzidel.dropinn.MainActivity"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
android:label="#string/app_name"
android:screenOrientation="sensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
This is my mainActivity:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen",R.drawable.loading_img);
super.init();
if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
fixJellyBeanIssues();
}
super.loadUrl("file:///android_asset/www/index.html",8000);
}
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
}
#TargetApi(16)
protected void fixJellyBeanIssues() {
System.out.println(super.appView.toString());
try {
super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true);
} catch(NullPointerException e) {
System.out.println(e.toString());
}
}
// catch an error and if try again 1x or quit
#Override
public void onReceivedError( int errorCode, String description, String failingUrl)
{
if(retryCount < 3) {
retryCount++;
System.out.println("Connection failed, trying again. Retry Count: "+retryCount);
super.loadUrl("file:///android_asset/www/listspace.html");
} else {
System.out.println("Sorry, it failed three times so I give up.");
super.loadUrl("file:///android_asset/www/fail.html");
}
return;
}
}
If don't want your application to restart you have to declare that explicidly in the android manifest like this
<activity android:name=".MyActivity"
android:configChanges="orientation"
android:label="#string/app_name">
However this is not recommended and considered as last resort.
Here you can read more how you should handle configuration changes
http://developer.android.com/guide/topics/resources/runtime-changes.html

Categories

Resources