Error while adding Galaxy Store review broadcast - java

I publish my apps and games on Galaxy Store some apps are here in this LINK
Using official (document)[https://developer.samsung.com/galaxy-store/customer-review/galaxy-store-review-broadcast.html] provided by Galaxy Store Developers I tried making a broadcaste of Rate this app in OnCreate inside MainActivity.java
Code I used in OnCreate:
ApplicationInfo ai =
getPackageManager().getApplicationInfo("com.sec.android.app.samsungapps",
PackageManager.GET_META_DATA);
int inappReviewVersion = ai.metaData.getInt("com.sec.android.app.samsungapps.review.inappReview", 0);
if (inappReviewVersion > 0){
// if inappReviewVersion is larger than zero, Galaxy Store supports in-app review function
} else {
// else, Galaxy Store does not support in-app review function
}
// 1. Check your review authority by Galaxy Store package
Intent intent = new Intent("com.sec.android.app.samsungapps.REQUEST_INAPP_REVIEW_AUTHORITY");
intent.setPackage("com.sec.android.app.samsungapps");
intent.putExtra("callerPackage", com.protecgames.htmleditor); // targetPacakge : your package name
sendBroadcast(intent);
// 2. Get result of authority checking from Galaxy Store package
IntentFilter filter = new IntentFilter();
filter.addAction("com.sec.android.app.samsungapps.RESPONSE_INAPP_REVIEW_AUTHORITY");
authorityReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// If true, you have authority to write review
boolean hasAuthority = intent.getBooleanExtra("hasAuthority", false);
// By using deeplinkUrlForReview, you can open review activity of Galaxy Store
String deeplinkUri = intent.getStringExtra("deeplinkUri");
}
}
Intent intent = new Intent();
intent.setData(Uri.parse(deeplinkUri)); // deeplinkUri, included in response intent
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
startActivity(intent);
The error while executing project:
----------
1. ERROR in /storage/emulated/0/.sketchware/mysc/601/app/src/main/java/com/my/newproject/MainActivity.java (at line 44)
ApplicationInfo ai = getPackageManager().getApplicationInfo("com.sec.android.app.samsungapps", PackageManager.GET_META_DATA); int inappReviewVersion = ai.metaData.getInt("com.sec.android.app.samsungapps.review.inappReview", 0); if (inappReviewVersion > 0){ // if inappReviewVersion is larger than zero, Galaxy Store supports in-app review function } else { // else, Galaxy Store does not support in-app review function } // 1. Check your review authority by Galaxy Store package Intent intent = new Intent("com.sec.android.app.samsungapps.REQUEST_INAPP_REVIEW_AUTHORITY"); intent.setPackage("com.sec.android.app.samsungapps"); intent.putExtra("callerPackage", com.protecgames.htmleditor); // targetPacakge : your package name sendBroadcast(intent); // 2. Get result of authority checking from Galaxy Store package IntentFilter filter = new IntentFilter(); filter.addAction("com.sec.android.app.samsungapps.RESPONSE_INAPP_REVIEW_AUTHORITY"); authorityReceiver = new BroadcastReceiver() { #Override public void onReceive(Context context, Intent intent) { // If true, you have authority to write review boolean hasAuthority = intent.getBooleanExtra("hasAuthority", false); // By using deeplinkUrlForReview, you can open review activity of Galaxy Store String deeplinkUri = intent.getStringExtra("deeplinkUri"); } } Intent intent = new Intent(); intent.setData(Uri.parse(deeplinkUri)); // deeplinkUri, included in response intent intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_INCLUDE_STOPPED_PACKAGES); startActivity(intent);
^
Syntax error, insert "}" to complete Statement
----------
1 problem (1 error)
I am using Sketchware v6.4.0 Beta 6 with add Source Directly block

Related

Launch Telegram app from Android application with message and recipient

I need to open Telegram from my own Android App prepopulating both the message and recipient (and not having to choose betwenn Chrome or Telegram),
I achieved the first one with this code:
final String appName = "org.telegram.messenger";
Intent tIntent = new Intent(Intent.ACTION_SEND);
tIntent.setType("text/plain");
tIntent.setPackage(appName);
tIntent.putExtra(Intent.EXTRA_TEXT, msg);
mUIActivity.startActivity(tIntent);
And the second one with this code:
Intent tIntent = new Intent(Intent.ACTION_VIEW);
tIntent.setData(Uri.parse("http://telegram.me/USERID"));
startActivity(tIntent);
(I removed all checks like isTelegramInstalled for simplicity)
I tried to mix the two methods
adding some intent extra such as msg we get to this code that will open Telegram, in one click, with pre-populated message and recipient:
Intent telegramIntent = new Intent(Intent.ACTION_SEND);
tIntent.setDataAndType(Uri.parse("http://telegram.me/username"), "text/plain");
final String appName = "org.telegram.messenger";
tIntent.setPackage(appName);
tIntent.putExtra(Intent.EXTRA_TEXT, "hello");
startActivity(tIntent);
...aaand it didn't work!
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=http://telegram.me/... flg=0x1 pkg=org.telegram.messenger clip={null T:hello} (has extras) }
Any idea how to achieve this?
Please try below function for open Telegram
public static void openTelegram(Activity activity, String userName) {
Intent general = new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.com/" + userName));
HashSet<String> generalResolvers = new HashSet<>();
List<ResolveInfo> generalResolveInfo = activity.getPackageManager().queryIntentActivities(general, 0);
for (ResolveInfo info : generalResolveInfo) {
if (info.activityInfo.packageName != null) {
generalResolvers.add(info.activityInfo.packageName);
}
}
Intent telegram = new Intent(Intent.ACTION_VIEW, Uri.parse("https://t.me/" + userName));
int goodResolver = 0;
// gets the list of intents that can be loaded.
List<ResolveInfo> resInfo = activity.getPackageManager().queryIntentActivities(telegram, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo info : resInfo) {
if (info.activityInfo.packageName != null && !generalResolvers.contains(info.activityInfo.packageName)) {
goodResolver++;
telegram.setPackage(info.activityInfo.packageName);
}
}
}
//TODO: if there are several good resolvers create custom chooser
if (goodResolver != 1) {
telegram.setPackage(null);
}
if (telegram.resolveActivity(activity.getPackageManager()) != null) {
activity.startActivity(telegram);
}
}
I hope this can help You!
Thank You.
In your case
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND dat=http://telegram.me/... flg=0x1 pkg=org.telegram.messenger clip={null T:hello} (has extras) }
Telegram chat activity class has a different name and you pass other activity name.
Find which class use telegram for chat activity and pass it on set package method

Permission Denial: opening provider android.support.v4.content.FileProvider

I was having some problem when trying to perform an application upgrade in Android emulator. The flow of the scenario is from an Activity, I will execute AsyncTask A which open up fragment A, then inside AsyncTask A, I will check if version upgrade is available.
If available and user selected "Okay" from fragment A, I will proceed to AsyncTask B to open up fragment B which show a message to user saying that upgrading is in process. In AsyncTask B doInBackground(), I will execute the install() and in onPostExecute(), I will show successful message.
In my AsyncTask B where I execute the install:
#Override
protected Boolean doInBackground(Void... params) {
boolean ret= viewmodel.installApk(mActivity);
return ret;
}
In my view model class:
public boolean installApk(Activity mActivity){
boolean success = false;
String fullPath = scanDirectoryForApk();
System.out.println("INSTALLING APK ......................... ");
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkURI = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".provider", new File(fullPath));
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
return true;
}
However, when I execute the code above, no error message was shown and the version upgrade is not working as well. It basically just restart the intent and there is no upgrade at all.
It does not prompt me for the permission to install new version as well. Any ideas?
By the way, my android emulator is not rooted and therefore I could not use the "su" command approach.
Thanks!
EDIT
As suggestion by #Sagar, I changed my code above to:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkURI = FileProvider.getUriForFile(mActivity, mActivity.getApplicationContext().getPackageName() + ".provider", new File(fullPath));
List<ResolveInfo> resInfoList = mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
mActivity.grantUriPermission(packageName, apkURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
intent.setDataAndType(apkURI, "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);
And I am getting new error message from logcat:
Error staging apk from content URI
java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{3883c8 9647:com.google.android.packageinstaller/u0a20} (pid=9647, uid=10020) that is not exported from UID 10085
The intent error message is telling me "There was a problem parsing package".
You can try to merge
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
into
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
I met the same issue as you, and this solution rescued myself.

Android - ArrayList containing Bluetooth devices remains empty

I am trying to discover all available bluetooth devices and pass to another activity.
However even when looking at the Android Docs, I am unable to figure out why I cannot discover any devices and my ArrayList remains empty.
OnClick execute this:
mBluetoothAdapter.startDiscovery();
My broadcast listener also works but nothing is every returned and ArrayList remains empty.
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
mDeviceList.add(device);
showToast("Found device " + device.getName());
}
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
if (state == BluetoothAdapter.STATE_ON) {
showToast("Enabled");
showEnabled();
}
}
if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
mDeviceList = new ArrayList<>();
mProgressDlg.show();
}
if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
mProgressDlg.dismiss();
Intent newIntent = new Intent(MainScreen.this, DeviceListActivity.class);
if (mDeviceList.isEmpty()){
Log.d("onReceive: ", "EMPTY");
}
newIntent.putParcelableArrayListExtra("device.list", mDeviceList);
startActivity(newIntent);
}
}
};
GIST
Answered my own question.
The fix was to turn location on with app permissions.
Apparently this is required for Android Marshmallow

API 23 (Android 6.0.1) InApp Billing: Service Intent must be explicit: Intent

I have been looking around and this seems to be a Android L related bug that was apparently solved solved using the code I already have.
When I try to call bindService I get:
Fatal Exception: java.lang.RuntimeException: Unable to resume activity
{MyActivity}: java.lang.IllegalArgumentException: Service Intent must
be explicit: Intent {
act=com.android.vending.billing.InAppBillingService.BINL }
This is the piece of code that causes the crash:
final Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
activity.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE);
It only happens on Android 6.0.1 and my target in gradle in 23 and I can't seem to understand what's wrong with that on API 23...
If you are using IabHelper classes. Go to startSetup Method in IabHelper.java. add below code
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
serviceIntent.setPackage("com.android.vending");
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
else {
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}
This method will help you turn the implicit intent into the explicit form. Inspired from SO answer: https://stackoverflow.com/a/26318757/1446466
bindServiceConn() method is creating a service.
* #param context
* #param implicitIntent - The original implicit intent
* #return Explicit Intent created from the implicit original intent
*/
public static Intent createExplicitFromImplicitIntent(Context context, Intent implicitIntent) {
// Retrieve all services that can match the given intent
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
// Make sure only one match was found
if (resolveInfo == null || resolveInfo.size() != 1) {
return null;
}
// Get component info and create ComponentName
ResolveInfo serviceInfo = resolveInfo.get(0);
String packageName = serviceInfo.serviceInfo.packageName;
String className = serviceInfo.serviceInfo.name;
ComponentName component = new ComponentName(packageName, className);
// Create a new intent. Use the old one for extras and such reuse
Intent explicitIntent = new Intent(implicitIntent);
// Set the component to be explicit
explicitIntent.setComponent(component);
return explicitIntent;
}
protected void bindServiceConn() {
//call this method
Intent intent = createExplicitFromImplicitIntent(context.getApplicationContext(), new Intent("com.android.vending.billing.InAppBillingService.BIND"));
context.bindService(intent, mServiceConn, Context.BIND_AUTO_CREATE);
}
protected void unbindServiceConn() {
context.unbindService(mServiceConn);
context=null;
}

"New Tag Collected" instead of reading tags of application - NFC android

I have a class, which creates conncection to NFC and two activites. Both of them creates an object of that class so they can connect to NFC.
Earlier it worked somehow but now I've got problem - my application doesn't do anything onNewIntent, even on the first activity. Instead of it, I can see "New tag collected" from build-in app called "Tags" (Nexus S).
What should I do?
class:
public NFCForegroundUtil(Activity activity)
{
super();
this.activity = activity;
mAdapter = NfcAdapter.getDefaultAdapter(activity
.getApplicationContext());
mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter ndef3 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
try
{
ndef2.addDataType("*/*");
}
catch (MalformedMimeTypeException e)
{
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {ndef, ndef2, ndef3 };
mTechLists = new String[][] { new String[] {
// android.nfc.tech.NfcV.class.getName(),
android.nfc.tech.NfcA.class.getName(),
android.nfc.tech.IsoDep.class.getName() } };
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
}
activity 1:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nfcForegroundUtil = new NFCForegroundUtil(this);
}
#Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
Intent i = new Intent(this, NfcDisplayLabelActivity2.class);
startActivity(i);
}
Go to settings -> Apps -> All -> Tags(in my case) -> disable
I had a similar problem when trying to open my app from an NFC tag. I had registered an intentfilter in my AndroidManifest.xml for the scheme "magicnfc" and yet it opened the Android OS Tags app instead of mine.
I discovered that the NFC intent (TECH_DISCOVERED in my case) had higher priority than a generic scheme-based intent filter. Because the Tags app registered TECH_DISCOVERED, it was getting opened instead of mine.
Luckily, apps can register for NDEF_DISCOVERED (a higher priority filter) and get opened instead of the Tags app.
That made my app open when I tapped the tag.
More info is here:
http://developer.android.com/guide/topics/connectivity/nfc/nfc.html
But I found that I had to override the function onNewIntent, with code like this:
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) {
String uri = intent.getDataString();
Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (rawMsgs != null) {
msgs = new NdefMessage[rawMsgs.length];
for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
}
}
For me, all I needed was:
String uri = intent.getDataString();
Good luck!
You can listen for all tags activated using the ACTION_TAG_DISCOVERED intent, rather than filtering for a specific one with the following code:
public NFCForegroundUtil(Activity activity)
{
super();
this.activity = activity;
mAdapter = NfcAdapter.getDefaultAdapter(activity
.getApplicationContext());
mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
0);
// See below
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}
From the NFCAdapter Documentation :
If you pass null for both the filters and techLists parameters that acts a wild card and will cause the foreground activity to receive all tags via the ACTION_TAG_DISCOVERED intent.
Your problem is when you initialise the intent i onNewIntent
The class should be itself, not the second class.
The right code should be :
#Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
Intent i = new Intent(this, NfcDisplayLabelActivity1.class);
startActivity(i);
}
I was seeing "New tag collected" from build-in app called "Tags" because my application didn't work properly.
When it works ok, it has higher priority than "Tags" and phone reads tags from my application. But when it works unproperly and phone collect a tag, "Tags" application is activated and "Tags" application talks to my device.
After repairing code, my app has higher priority and phone reads tags using my application.

Categories