Unable to start webserver service in android - java

i am developing a android app that makes a phone webserver it works fine when i use it without the service but i want to use service so that my webserver runs in background this is my code please have a look at it..
Serivice runner class:
package dolphin.developers.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import dolphin.devlopers.com.R;
public class web extends Activity implements OnClickListener {
public static final int progress_bar_type1 = 0;
private static final String TAG = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.hotmail);
Button btnShowProgressa;
Button buttonStop = (Button) findViewById(R.id.button1ad);
buttonStop.setOnClickListener(this);
btnShowProgressa = (Button) findViewById(R.id.button2);
btnShowProgressa.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch (arg0.getId()) {
case R.id.button2:
Log.d(TAG, "onClick: starting srvice");
startService(new Intent(this, webser.class));
break;
case R.id.button1ad:
Log.d(TAG, "onClick: stopping srvice");
stopService(new Intent(this, webser.class));
break;
}
}
}
Webserver service:
package dolphin.developers.com;
import java.io.File;
import java.io.IOException;
import android.app.Service;
import android.content.Intent;
import android.os.Environment;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class webser extends Service {
Thread hi;
private static final String TAG = null;
JHTTP pro;
#Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
#Override
public void onCreate() {
Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
hi= new Thread(){
public void run(){
try{
File documentRootDirectory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/");
pro = new JHTTP(documentRootDirectory, 1234);
}
catch(IOException e ){
e.printStackTrace();
}
}
}; hi.start();
}
#SuppressWarnings("deprecation")
#Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
readysteadypo.stop();
pro.stop();
}
#Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
pro.start();
}
}
Manifest file:
<Service
android:name="dolphin.developers.com.webser"/>
Logcat:
08-05 13:04:12.221: W/ActivityManager(73): Unable to start service Intent { cmp=dolphin.devlopers.com/dolphin.developers.com.hot1 }: not found

The Problem is solved now. I added intent filter action and it is working fine.
Here goes the code:
<service android:name="dolphin.developers.com.webser" android:enabled="true">
<intent-filter>
<action android:name="dolphin.developers.com.webserv"></action>
</intent-filter>
</service>

Related

How do I access my UI from MainActivity from Broadcast Receiver class

I am new to Android Studio and I am creating a custom notification app, and I wanted to use the EditText from my MainActivity class in Broadcast Receiver class. How can I do that?
Broadcast Receiver code:
`package com.example.notificationscreator;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.widget.EditText;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder Build = new NotificationCompat.Builder(context, "Notified");
Build.setSmallIcon(R.drawable.ic_stat_name);
Build.setContentTitle("");
Build.setStyle(new NotificationCompat.BigTextStyle().bigText(""));
NotificationManagerCompat Managercompats = NotificationManagerCompat.from(context);
Managercompats.notify(1, Build.build());
}
}`
Main activity code:
`package com.example.notificationscreator;
import static com.example.notificationscreator.R.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import android.app.AlarmManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Calendar;
import java.util.Random;
public class MainActivity2 extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_main2);
Button btnmain = findViewById(R.id.button4);
Button Displaynotif = findViewById(R.id.button3);
EditText Timedisplay = findViewById(R.id.editTextTime);
Integer Time = Integer.parseInt(Timedisplay.getText().toString());
btnmain.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Backmainpage();
}
});
if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel("Notified","Notification", NotificationManager.IMPORTANCE_HIGH);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
Displaynotif.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
int Randnum = new Random().nextInt(80);
Intent intent= new Intent(MainActivity2.this,MyReceiver.class);
PendingIntent pendingintention = PendingIntent.getBroadcast(MainActivity2.this,0, intent,0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
long timeonclick = System.currentTimeMillis();
long timeafterclick = 10000;
am.set(AlarmManager.RTC_WAKEUP,timeonclick+timeafterclick,pendingintention);
}
});
}
public void Backmainpage(){
Intent intention2 = new Intent(this,MainActivity.class);
startActivity(intention2);
}
}`
I've tried recalling Main Activity using
MainActivity2 Mainactivity = new MainActivity2();
but I still can't access the UI from Main Activity
You can use another BroadcastReceiver to communicate with your activity like below example.
add the following code inside your broadcast receiver.
#Override
public void onReceive(Context context, Intent intent) {
//... your other code
Intent intent = new Intent();
intent.setAction("CustomAction"); // use your action name
intent.putExtra("key", "Value"); // you can pass data like this
context.sendBroadcast(intent); // fire broadcast receiver
}
Now, register your custom broadcast receiver from Activity
#Override
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction("CustomAction"); // use your custom action name
BroadcastReceiver updateUIReciver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
//You will get your data here
//Update UI based on your data.
if (intent != null) {
String data = intent.getStringExtra("key");
}
}
};
registerReceiver(updateUIReciver, filter); // register broad cast receiver.
}
public class MainActivity2 extends AppCompatActivity {
EditText Timedisplay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.activity_main2);
Timedisplay = findViewById(R.id.editTextTime);
//register your broadcast here
LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("messageevent"));
}
}
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, final Intent intent) {
// Get extra data included in the Intent
String message = intent.getStringExtra("key");
Log.e(TAG, "Got message: " + message);
if(message != null && !message.isEmpty()) {
//Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
String timedisplay = Timedisplay.getText();
}
}
};
//call this from anywhere you want to trigger the broadcoast
Intent i = new Intent("messageevent");
// You can also include some extra data.
i.putExtra("key", "value");
LocalBroadcastManager.getInstance(CheckUpdate.this).sendBroadcast(i);

Android wear OS retrieving stepcounter in background

I am trying to retrieve step counts from a smartwatch and push it to API. I was able to retrieve and push the data when I open the app. But once it is not activated, then it will not send any data. I am trying to use the android service to run the app in the background so that it will send the data continuously. I have given all the permissions and enabled them.
This is MainActivity.java
package com.example.stepcounter;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected void onResume() {
super.onResume();
}
protected void onPause() {
super.onPause();
}
protected void onDestroy() {
super.onDestroy();
}
public void onPressStartService(View v){
Intent intent = new Intent(this, MyService.class);
startService(intent);
}
public void onPressStopService(View v){
stopService(new Intent(getApplicationContext(), MyService.class));
}
}
And this is MyService.java
package com.example.stepcounter;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
public class MyService extends Service implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mSensor;
private String HelloData;
private TextView mTextView;
private boolean isSensorPresent;
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
mSensorManager = (SensorManager)this.getSystemService(Context.SENSOR_SERVICE);
if(mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE) != null) {
mSensor = mSensorManager.getDefaultSensor(69680);
isSensorPresent = true;
} else {
isSensorPresent = false;
}
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
return START_STICKY;
}
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onSensorChanged(SensorEvent event) {
mTextView.setText("Heart Rate: " + String.valueOf(event.values[0]));
HelloData = (String) String.valueOf(event.values[0]);
if(!HelloData.contains("0.0")){
postDataUsingVolley(HelloData);
}
}
#Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
private void postDataUsingVolley(String ranData) {
String url = "https://test.com";
RequestQueue queue = Volley.newRequestQueue(this);
JSONObject postData = new JSONObject();
try {
postData.put("data", ranData);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, postData, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
System.out.println(response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
queue.add(jsonObjectRequest);
}
}
I have also added the following in AndroidManifest.xml
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"></service>
It works for 30 seconds, send the data and once the watch goes inactive, it stops sending data. Any idea what is wrong with this?
You need to unregister your Sensor during onPause:
#Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(this);
}
Also, if you unregister, you need to use your boolean activityRunning.

Trying to turn on Bluetooth,However the application getting crashed

I'm Trying to turn on bluetooth on my application, However when I click the button submit the application is getting crashed and showing error as java.lang.nullpointerexception
Error code
FATAL EXCEPTION: main
Process: com.example.smartaams, PID: 4094
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothAdapter.isEnabled()' on a null object reference
at com.example.smartaams.MarkAttendance.enableDisableBT(MarkAttendance.java:131)
at com.example.smartaams.MarkAttendance$1.onClick(MarkAttendance.java:92)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22265)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Script
package com.example.smartaams;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.ByteArrayBuffer;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Calendar;
public class MarkAttendance extends Activity {
int year;
int month;
int day;
static final int DATE_DIALOG_ID=999;
String class_item,sub_item;
Button submitbutton,backbutton;
EditText tvDisplayDate,tvTopic;
Spinner spclassname,spsubject,session;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
ArrayList<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
String mydate=java.text.DateFormat.getDateInstance().format(Calendar.getInstance().getTime());
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mark_attendance);
tvDisplayDate = (EditText) findViewById(R.id.currentdate);
tvTopic = (EditText) findViewById(R.id.topic);
final Calendar c = Calendar.getInstance();
int yy = c.get(Calendar.YEAR);
int mm = c.get(Calendar.MONTH);
int dd = c.get(Calendar.DAY_OF_MONTH);
// set current date into textview
tvDisplayDate.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(yy).append(" ").append("-").append(mm + 1).append("-")
.append(dd));
submitbutton = (Button) findViewById(R.id.submit);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
submitbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.d(TAG, "onClick: enabling/disabling bluetooth.");
enableDisableBT();
}});
}
private static final String TAG = "Attendance";
BluetoothAdapter mBluetoothAdapter;
// Create a BroadcastReceiver for ACTION_FOUND
private final BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
// When discovery finds a device
if (action.equals(mBluetoothAdapter.ACTION_STATE_CHANGED)) {
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, mBluetoothAdapter.ERROR);
switch(state){
case BluetoothAdapter.STATE_OFF:
Log.d(TAG, "onReceive: STATE OFF");
break;
case BluetoothAdapter.STATE_TURNING_OFF:
Log.d(TAG, "mBroadcastReceiver1: STATE TURNING OFF");
break;
case BluetoothAdapter.STATE_ON:
Log.d(TAG, "mBroadcastReceiver1: STATE ON");
break;
case BluetoothAdapter.STATE_TURNING_ON:
Log.d(TAG, "mBroadcastReceiver1: STATE TURNING ON");
break;
}
}
}
};
public void enableDisableBT() {
if (mBluetoothAdapter == null) {
Log.d(TAG, "enableDisableBT: Does not have BT capabilities.");
}
if (mBluetoothAdapter.isEnabled()) {
Log.d(TAG, "enableDisableBT: enabling BT.");
Intent enableBTIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBTIntent);
IntentFilter BTIntent = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(mBroadcastReceiver1, BTIntent);
}
if (mBluetoothAdapter.isEnabled()) {
Log.d(TAG, "enableDisableBT: disabling BT.");
mBluetoothAdapter.disable();
IntentFilter BTIntent = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
registerReceiver(mBroadcastReceiver1, BTIntent);
backbutton = (Button) findViewById(R.id.back);
backbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i=new Intent(MarkAttendance.this,StudentHome .class);
startActivity(i);
}
});
spclassname.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
#Override
public void onItemSelected(AdapterView<?>spclassname, View view, int position, long id) {
// On selecting a spinner item
class_item =spclassname.getSelectedItem().toString();
}
#Override
public void onNothingSelected(AdapterView<?> parent)
{
// TODO Auto-generated method stub
}
});
spsubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
#Override
public void onItemSelected(AdapterView<?> spsubject, View view, int position, long id) {
// On selecting a spinner item
sub_item = spsubject.getSelectedItem().toString();
}
#Override
public void onNothingSelected(AdapterView<?> parent)
{
// TODO Auto-generated method stub
}
});
session.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> session, View view, int position, long id) {
// On selecting a spinner item
sub_item = session.getSelectedItem().toString();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
}
}
Please help
PS: I'm very new to coding, and I'm using someone else project
Make sure that you have added permissions for Bluetooth in your AndroidManifest.xml file as follows :
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
And you need to check if bluetooth is enabled, if not, request to enable it.
So, instead of checking (mBluetoothAdapter.isEnabled()) , you need to check not condition as follows and need to call Bluetooth enable Intent:
(!mBluetoothAdapter.isEnabled()).
Also, you need to add return statement if you get the instance of BluetoothAdapter as null. See the code below :
if (mBluetoothAdapter == null) {
Log.d(TAG, "enableDisableBT: Does not have BT capabilities.");
return; // missing statement
}
I hope this will help you.

Error: View cannot be applied to Intent

I'm new to Android App Development and creating a simple service app. It has a button to start service and a button to stop service with their repective methods. Following is my code:
App3_main.java
package eg.app3;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class App3_main extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app3_main);
}
public void startservice(View view)
{
Intent intent = new Intent(this,MyService.class);
startservice(intent); //this is where I'm getting the error mentioned in the title
}
public void stopservice(View view)
{
Intent intent = new Intent(this,MyService.class);
stopservice(intent); //this is where I'm getting the error mentioned in the title
}
}
MyService.java
package eg.app3;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
public class MyService extends Service {
public MyService() {
}
#Override
public void onCreate() {
super.onCreate();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this,"Service Started",Toast.LENGTH_LONG).show();
return START_STICKY;
}
#Override
public void onDestroy() {
Toast.makeText(this,"Service Stopped",Toast.LENGTH_LONG).show();
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
Please guide me where I'm wrong.
Replace:
startservice(intent);
with:
startService(intent);
Then, replace:
stopservice(intent);
with:
stopService(intent);
Like most programming languages, Java is case-sensitive.

Testing android in app billing doesn't show any products when bebugging

I have a simple app that has an unlock feature in it. When a user purchases this they can unlock more content in the app.
When I debug the app I don't get any errors, but I am unable to retrieve a list of products using the google billing services.
On my main activity I would like to check if the user has all ready purchased the "upgrade" if they have do something with that information.
I have been following the api documentation but its not really helping.
In App Billing Reference
Implementation
Testing
I have 1 item in my In-app products, I have followed the testing document and added an apk to my Alpha testing. The problem here is that apk cant have debugging enabled, so when I use the debugger in android studio the app may perform differently??
I think my code is OK,but any help or guidance in how to test this would be great.
MainActivity.java
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import com.android.vending.billing.IInAppBillingService;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends Activity {
IInAppBillingService mService;
ServiceConnection connection;
Intent serviceIntent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
Button start = (Button) findViewById(R.id.startgame);
Button settings = (Button) findViewById(R.id.about);
start.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), StartGame.class);
startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
});
settings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), Settings.class);
startActivity(i);
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
}
});
/// check for pro unlock
serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
// first this
connection = new ServiceConnection() {
#Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
#Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d("BILLING", "Connected");
//purchse info
mService = IInAppBillingService.Stub.asInterface(service);
checkPurchaseInfo();
}
};
bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE);
}
private void checkPurchaseInfo() {
try {
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
int responseCode = ownedItems.getInt("RESPONSE_CODE");
Log.d("BILLING","Request Code: " + responseCode);
if(responseCode == 0){
ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");
Log.d("OWNED",ownedSkus.toString());
Log.d("purcahseList",purchaseDataList.toString());
Log.d("SIGNLIST",signatureList.toString());
/////////
//all of these arrays come back as empty []
////////
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
#Override
public void onDestroy() {
super.onDestroy();
if (connection != null) {
unbindService(connection);
}
}
}

Categories