Marshmallow is asking for storage permission everytime even once given - java

I have created a new application and every page has a share button on it and on clicking share button it captures the screenshot and makes it shares via intent and over clicking on share button it ask for permission and once given it works smoothly for other devices except Android 6 as even once given permission Android 6 asks for it again and again
The code I have used on every page
Manifest:<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
OnClick(View v) {
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1);
SHARE();
}
This code is written in 5 pages a five-page am having five page News category and on clicking on share button it should ask for permission but once given it should not ask

The problem is that you are requesting permissions in that method. You need to check to see if permissions have been granted and only then request them.
See here for details https://developer.android.com/training/permissions/requesting

Related

How do I know if the app has been downloaded from Google Play once

I have an Android mobile application that works with the membership system.
There are links to other mobile applications and games in my application.
With Packet Manager, I can check whether the application in the link is installed on the phone. My goal is to check whether users have downloaded the game and mobile applications on the device by clicking the links in my application.
If they downloaded the application in the given link once (first time), they will earn 10 points. If they download the same application many times, they will be considered as one time.
I wanted to ask you that If users download an app more than once, how do I count it just one time?
private boolean appInstalledOrNot(String uri) {
PackageManager pm = getPackageManager();
boolean app_installed = false;
try {
pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
app_installed = true;
} catch (PackageManager.NameNotFoundException e) {
app_installed = false;
}
return app_installed;
}
public void go(View view) {
boolean installed = appInstalledOrNot("com.dousoftware.pubgtyolar");
//loaded
if (installed) {
Toast.makeText(this, "Loaded", Toast.LENGTH_SHORT).show();
} else {
Intent viewIntent = new Intent("android.intent.action.VIEW",
Uri.parse("https://play.google.com/store/apps/details?
id = com.dousoftware.pubgtyolar "));
startActivity(viewIntent); Toast.makeText(this, "Not Loaded", Toast.LENGTH_SHORT).show();
}
}
The short answer is: you can't.
There is no way to know, locally, on an Android device, how many times the user installed or uninstalled an app.
The long answer is that there may be some workarounds, each with its own advantages and disadvantages.
While your app is installed, you could register to ACTION_PACKAGE_ADDED and ACTION_PACKAGE_REMOVED broadcasts.
These will be called every time the user installs or removes any app.
They have EXTRA_PACKAGE_NAME that contains the app package name.
This however, presents some problems:
This will only work while your app is installed and the user has opened your app at least once.
You will receive this broadcast for any app, and will have to filter the results yourself.
If the user clears data or uninstalls and reinstalls your app, you will lose count.
Another way, and how most apps do it, is by using a referral framework.
One example is Iron Source which will let you set up rewards for installing and using different apps.
If the other app is also yours, you can simply use Firebase.
Note however, that referral tracking compromises user privacy, so you have to be careful to comply with any local laws such as GDPR.
Also, using these frameworks may cost money.
If user click link
Check that user don't have this application
Redirect to store page.
Set in the config file that this link has been clicked
If user install application and Script triggers (eg on app opening) add points. Add points only if Link has been marked as clicked.
Mark the link in config file as used to not give more points from the same app.
You can store this data on your server to avoid eg uninstalling abuse
Simply save somewhere information that link has been used

Android Q - Privacy change activity start through NFC

https://developer.android.com/preview/privacy/background-activity-starts
From this, it results that my payment app, which shows an Activity when a NFC transaction is performed, will not be able anymore to show anything to the user.
Has anyone have a clue what would be the new approach ?
Thanks!
I currently use the NFC service and it starts an Activity intent.
Intent intent = new Intent(mApplicationContext, PaymentActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
mApplicationContext.startActivity(intent);
The Activity should be shown. It works now, but from Android Q, it won't
According to the link, if you are having a HostApduService, then your app should work the same in Android Q.
If that is not your case, the simplest work around is to get "Draw over other apps" permissions. You can open activities if the app has been granted the SYSTEM_ALERT_WINDOW permission by the user. I have tested this and working.
Technically, you are showing something on top of other apps without user's interaction, so this might be the right way to go.

How I can Hide "this may cost you money"

I am developing native android app using Eclipse, I add the following permission on Android Manifest
<uses-permission android:name="android.permission.CALL_PHONE" />
Then, I get the following message when I am trying to install the android app on my device:
Directly call phone numbers this may cost you money
could I do something to hide this message because I think this is not friendly for users? maybe i need to use another permission, which is the closer one with no permission is required?
I used the following code on my adapter:
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(PhoneCall));
v.getContext().startActivity(callIntent); }
});
You are welcome to remove the CALL_PHONE permission. Then the message will not appear when the app is installed. All permissions trigger installation warnings, not just CALL_PHONE.
Note that your app only needs the CALL_PHONE permission if you use stuff like the ACTION_CALL Intent. ACTION_DIAL can also be used to place phone calls, but since it allows the user to be involved, no permission is required.
EDIT
Use this format to specify the number and user will have only to click green button "Call".
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:0123456789"));
startActivity(intent);

Facebook sdk Java - adding extended permissions with LoginButton

My app works well, but I also would like to list the pages I admin in Facebook. I add the manage_pages permission, to the login, and then I want to list the pages.
It works well on the Facebook Graph API Exlorer-
SELECT manage_pages FROM permissions WHERE uid = me()
I got manage_pages=1. Then I listed my pages-
SELECT page_id FROM page_admin WHERE uid =me()
I get all the page ids I admin.
But in my app I tried to add the manage_pages permission, and when I check the permissions in the app I get manage_pages=0
Here are a few line of my code:
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("manage_pages"));
String fqlQuery = "SELECT manage_pages FROM permissions WHERE uid = me()";
Log.d("LINK_RESULT", (String) object.get("manage_pages"));
I get manage_pages=0, but when I change it to "email", I get email=1
How do I add the extended permissions to the LoginButton?
See the section Request publish permissions in this link. It says that manage_pages is a publish permission. Its not a read permission!
Another thing- With the new SDKs, you need to separate the read and the write permissions. You can first open session for read, get what you want and then open for publish. According to the facebook documentation-
If any publish permissions are included, the login attempt by the user will fail. The LoginButton can only be associated with either read permissions or publish permissions, but not both. Calling both setReadPermissions and setPublishPermissions on the same instance of LoginButton will result in an exception being thrown unless clearPermissions is called in between.
You need to call clearPermissions() in between the two calls. Hope it helps. Good luck!

Sending email through intent without having to press send button

Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)

Categories

Resources