I am trying to write in file after android device boots. I have checked everything related to this topic here but none of them worked for me. My phone is Huawei Honor (H30-U10) and it's rooted. Android version 4.2.2. Here is my code:
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bog.ddrc.technicianmobile"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name="bog.ddrc.technicianmobile.App"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="bog.ddrc.technicianmobile.activities.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:enabled="true"
android:name="bog.ddrc.technicianmobile.StartTMServiceAtBootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
StartTMServiceAtBootReceiver.java:
public class StartTMServiceAtBootReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String data = "text";
File path = Environment.getExternalStorageDirectory();
File file = new File(path, "test.txt");
try {
OutputStream os = new FileOutputStream(file);
os.write(data.getBytes());
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Remove
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
from your <receiver> block.
After trying all of mentioned answers and tricks, I finally find why the code is not work in my phone. Some Android phones like "Huawei Honor 3C Android 4.2.2" have a Statup Manager menu in their settings and your app must be checked in the list. :)
Related
I'm working with GeckoView and met problem with installing AddOns. As suggested on Documentation, I've provided XPI compatible with Android, but nothing changes. Copying file to Assets doesn't make a change. Browser doesn't acknowledge WebExtension.
private fun setupGeckoView() {
geckoSession?.permissionDelegate = object : GeckoSession.PermissionDelegate {
override fun onContentPermissionRequest(
session: GeckoSession,
perm: GeckoSession.PermissionDelegate.ContentPermission
): GeckoResult<Int>? {
return super.onContentPermissionRequest(session, perm)
}
}
geckoView = findViewById(R.id.geckoView)
val runtime = GeckoRuntime.create(this)
runtime.settings.consoleOutputEnabled = true
runtime.webExtensionController.promptDelegate = PromptListener(runtime.webExtensionController)
runtime.webExtensionController
.install("https://addons.mozilla.org/android/downloads/file/3719055/youtube_high_definition-85.0.0-an+fx.xpi")
geckoSession.open(runtime)
geckoView.setSession(geckoSession)
geckoSession.loadUri("https://www.youtube.com")
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gv.webapp">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<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/Theme.webapp">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--<provider
android:authorities="com.gv.webapp"
android:name="com.gv.webapp.Provider">
<grant-uri-permission android:path="string"
android:pathPattern="string"
android:pathPrefix="string" />
</provider>-->
</application>
</manifest>
I'm checking logs and the result is confusing. I've got prompt that WebExtension is installed, but when I looking at controller.list() it's empty.
You may be missing a PermissionDelegate:
geckoSession?.permissionDelegate = object : GeckoSession.PermissionDelegate {
override fun onContentPermissionRequest(
session: GeckoSession,
perm: GeckoSession.PermissionDelegate.ContentPermission
): GeckoResult<Int>? {
return super.onContentPermissionRequest(session, perm)
}
}
Permission delegate allows you to handle requests from Gecko for any permission that needs handling.
I've searching for many other answers about this failure, and no one of them solved my problem.
I have two apps, the app1 is implemented with Content Provider, and one database called students. This db is accessed normally inside app1.
But, when I fetch database from the app2, I've facing this error:
Failed to find provider info for
com.example.a436236692.myapplication.StudentsProvider
The code that are fetching students db is the same from both apps:
Uri myURI = Uri.parse("content://com.example.a436236692.myapplication.StudentsProvider/students");
ContentProviderClient myCR = getContentResolver().acquireContentProviderClient(myURI);
try {
Cursor c = myCR.query(myURI, null, null, null, "name");
if (c.moveToFirst()) {
do{
Toast.makeText(this,
c.getString(c.getColumnIndex(Constantes._ID)) +
", " + c.getString(c.getColumnIndex( Constantes.NAME)) +
", " + c.getString(c.getColumnIndex( Constantes.GRADE)),
Toast.LENGTH_SHORT).show();
} while (c.moveToNext());
}
} catch (RemoteException e) {
e.printStackTrace();
}
Debuging app 2, myCR comes with null. Them crashes application.
With my searches of this problem, I found many information that I need to grant access from package of Content Provider. Below are my manifests:
Manifest form app1:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a436236692.myapplication" >
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.READ_DATABASE"/>
<uses-permission android:name="android.permission.WRITE_DATABASE"/>
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"/>
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"/>
<permission android:name="com.example.a436236692.myapplication.StudentsProvider" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:permission="com.example.a436236692.myapplication.StudentsProvider">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:name="com.example.a436236692.myapplication.StudentsProvider"
android:authorities="com.example.a436236692.myapplication.StudentsProvider"
android:enabled="true"
android:multiprocess="true"
android:readPermission="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"
android:writePermission="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"
android:exported="true" />
</application>
</manifest>
Manifest form app2:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.a436236692.testes">
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"/>
<uses-permission android:name="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"/>
<uses-permission android:name="android.permission.READ_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.WRITE_USER_DICTIONARY"/>
<uses-permission android:name="android.permission.READ_DATABASE"/>
<uses-permission android:name="android.permission.WRITE_DATABASE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:readPermission="com.example.a436236692.myapplication.StudentsProvider.READ_DATABASE"
android:writePermission="com.example.a436236692.myapplication.StudentsProvider.WRITE_DATABASE"
android:theme="#style/AppTheme">
<activity android:name="com.example.a436236692.testes.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.a436236692.testes.ContentProviderExampleActivity" />
</application>
</manifest>
Even with permissions, inside the app1, Read and Write and other things, that I include inside the manifests, they do not affect the result.
Thanks
I'm using Parse Unity SDK for Android.
I've managed to register the device successfully.
void Start() {
//Parse Installation
if (ParseInstallation.CurrentInstallation != null && !string.IsNullOrEmpty(ParseInstallation.CurrentInstallation.DeviceToken))
{
Debug.Log("Device Token : " + ParseInstallation.CurrentInstallation.DeviceToken);
}
else
{
ParseInstallation installation = ParseInstallation.CurrentInstallation;
installation.Channels = new List<string> { Config.Instance.GetUserInfo().GetEmail() };
installation.SaveAsync().ContinueWith(t => {
if (t.IsFaulted || t.IsCanceled)
{
Debug.Log("Push subscription failed.");
}
else
{
Debug.Log("Push subscription success.");
}
});
//installation.
}
}
Only to discover that the notification is "received" but not being displayed neither in the app nor in the notifications bar.
I/GCM ( 1285): GCM message com.ahmed.app 0:1433935471473270%3f8fc5dbf9fd7ecd
I/ParsePushService( 7057): Push notification received. Payload: {"alert":"test","push_hash":"098f6bcd4621d373cade4e832627b4f6"}
I/ParsePushService( 7057): Push notification is handled while the app is foregrounded.
W/GCM-DMM ( 1285): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.ahmed.app (has extras) }
Also, Unity does not receive the notification (see code)
void Awake() {
ParsePush.ParsePushNotificationReceived += (sender, args) => {
#if UNITY_ANDROID
AndroidJavaClass parseUnityHelper = new AndroidJavaClass("com.parse.ParseUnityHelper");
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
//Debugging the payload
Debug.Log("Calling Parse from Unity and Payload is : " + args.StringPayload);
// Call default behavior.
parseUnityHelper.CallStatic("handleParsePushNotificationReceived", currentActivity, args.StringPayload);
#endif
};
}
This event doesn't get triggered.
Here's my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ahmed.app" android:theme="#android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature" android:name="com.ahmed.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.ahmed.app.permission.C2D_MESSAGE" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name" android:debuggable="false">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="#string/app_name" android:screenOrientation="portrait" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
<activity android:name="com.outlinegames.unibill.PurchaseActivity" android:label="#string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
<service android:name="com.parse.ParsePushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.ahmed.app" />
</intent-filter>
</receiver>
</application>
Any idea what's the problem?
I have answered the same kind of question, I just wanted to let you know.
Parse Unity Push Sample not working
Basically, this line of your code is wrong:
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
You have to replace it by
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("com.unity3d.player.UnityPlayerNativeActivity");
Rather than downloading the SDK manually, I've downloaded the Parse Push sample project and copied the files to my project. Using the SDK 1.5.2 sample project, it works now.
I write a program provider a provider for another apps of our company. The provider need a permission to access the data.
We also have a interface need use NFC send json data to another devices.
When we access the provider in CreateNdefMessageCallback.createNdefMessage like
#Override
public NdefMessage createNdefMessage(NfcEvent event) {
Context context = this;
ContentResolver resolver = context.getContentResolver();
Cursor cursor = resolver.query(Uri.parse("content://demo/data-lists"),
null,
null,
null,
null);
// FIXME Strange: Will never goes here ...
mMessage = getMessage(cursor);
NdefMessage msg = new NdefMessage(
new NdefRecord[] {
createMimeRecord(mMimeType, mMessage.getBytes())
});
return msg;
}
There is very strange, we never get a cursor until remove the permission.
Permission Declear
<permission
android:name="com.client.permission.MY_PERMISSION"
android:label="#string/provider_label"
android:protectionLevel="signatureOrSystem" />
Request permision
<uses-permission android:name="com.client.permission.MY_PERMISSION" />
Provider permission declear
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"
android:permission="com.client.permission.MY_PERMISSION" />
Currenty the provider and the NFC-send activity in the same application and read the provider data will but the NFC callback.
And if I remove the permission for the provider, this will work fine.
like the
Provider without permission
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"/>
Please help.
Thanks.
UPDATED 2013-03-14
It's very strange. I found this issue only when the provider and the NFC Activity in the same application. like this.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcdemo"
android:versionCode="6"
android:versionName="build-svn291" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<permission
android:name="com.client.permission.MY_PERMISSION"
android:label="#string/provider_label"
android:protectionLevel="signatureOrSystem" />
<uses-permission android:name="com.client.permission.MY_PERMISSION" />
<activity
android:name=".ui.MainTabActivity"
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>
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"
android:permission="com.client.permission.MY_PERMISSION" />
</manifest>
But if I use two separated application, it works will like.
<!-- Application Provider -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcdemo.provider"
android:versionCode="6"
android:versionName="build-svn291" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<permission
android:name="com.client.permission.MY_PERMISSION"
android:label="#string/provider_label"
android:protectionLevel="signatureOrSystem" />
<provider
android:name=".provider.DemoProvider"
android:authorities="demo"
android:multiprocess="true"
android:permission="com.client.permission.MY_PERMISSION" />
</manifest>
<!-- Application UI -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nfcdemo.ui"
android:versionCode="6"
android:versionName="build-svn291" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<uses-permission android:name="com.client.permission.MY_PERMISSION" />
<activity
android:name=".ui.MainTabActivity"
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>
</manifest>
I am successfully calling my first Activity from my AIR Native Extension, however, when I try to call the second one, I am getting the Permission Denial error (see logcat screenshot). I have tried everything I have found suggested on this site, so posting question.
02-12 15:43:22.430: I/ActivityManager(271): START {act=android.intent.action.RUN cmp=com.cno.android.map/.AddMarkerActivity (has extras) u=0} from pid 14173
02-12 15:43:22.440: W/ActivityManager(271): Permission Denial: starting Intent { act=android.intent.action.RUN cmp=com.cno.android.map/.AddMarkerActivity (has extras) } from ProcessRecord{4147a718 14173:air.TestAndroidExtension.debug/u0a75} (pid=14173, uid=10075) not exported from uid 10072
Here is my manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cno.android.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<!-- End of copy. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<activity
android:name="com.cno.android.map.InitMapActivity"
android:label="#string/title_activity_init_map" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.cno.android.map.AddMarkerActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.RUN"/>
</intent-filter>
</activity>
</application>
Things to note:
I first tried AddMarkerActivity without any intent-filter defined. Not having ANY luck, I began experimenting with the RUN action. I have commented everything out in AddMarkerActivity except for one logcat message that says "HELLO" in the onCreate method. As you can see my Activity is not duplicated in the manifest and exported is set to true.
And finally, here is how I am calling the Activity:
public class AddAnnotationFunction implements FREFunction {
public static final String TAG = "AddAnnotationFunction";
public final static String EXTRA_MARKER = "com.cno.nativemap.functions.marker";
#Override
public FREObject call(FREContext context, FREObject[] args) {
Intent intent = new Intent();
intent.setClassName("com.cno.android.map", "com.cno.android.map.AddMarkerActivity");
Log.d(TAG, "Starting Map Activity- add marker");
intent.setAction("android.intent.action.RUN");
intent.putExtra(EXTRA_MARKER, new GeoMarker(args));
context.getActivity().startActivity(intent);
return null;
}
}