Android browser unable to open web page - android

Hello i am new to android and i written a small app for "Simple web Browser".
but my browser is unable to open the page and it's showing error like no network available(Web Page not available) even wifi is on and normal browser is working on that device.
please check the code below::
SimpleBrowser.java
package com.thenewboston.travis;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class SimpleBrowser extends Activity implements OnClickListener{
Button bGo,bBack,bForward,bHistory,bRefresh;
EditText et;
WebView wb;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.simplebrowser);
bGo = (Button)findViewById(R.id.go);
bBack = (Button)findViewById(R.id.bBack);
bForward = (Button)findViewById(R.id.bForward);
bHistory = (Button)findViewById(R.id.bHistory);
bRefresh = (Button)findViewById(R.id.bRefresh);
et = (EditText)findViewById(R.id.editAddress);
wb = (WebView)findViewById(R.id.webView);
wb.setWebViewClient(new ourViewClient());
bGo.setOnClickListener(this);
bBack.setOnClickListener(this);
bForward.setOnClickListener(this);
bHistory.setOnClickListener(this);
bRefresh.setOnClickListener(this);
//wb.loadUrl("http://www.gmail.com");
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId())
{
case R.id.go:
String website = et.getText().toString();
wb.loadUrl(website);
break;
case R.id.bBack:
if(wb.canGoBack())
wb.goBack();
break;
case R.id.bForward:
if(wb.canGoForward())
wb.goForward();
break;
case R.id.bHistory:
wb.clearHistory();
break;
case R.id.bRefresh:
wb.reload();
break;
}
}
}
ourViewClient.java
package com.thenewboston.travis;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class ourViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
and ....
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.thenewboston.travis"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="KCRaju"
android:theme="#style/AppTheme">
<activity
android:name="com.thenewboston.travis.Splash"
android:label="KCRaju"
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=".StartingPoint"
android:label="KCRaju" >
<intent-filter>
<action android:name="com.thenewboston.travis.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Menu"
android:label="KCRaju" >
<intent-filter>
<action android:name="com.thenewboston.travis.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".prefs"
android:label="KCRaju" >
<intent-filter>
<action android:name="com.thenewboston.travis.prefs" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".About"
android:label="KCRaju"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.thenewboston.travis.About" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".TextPlay" android:label="#string/app_name" >
</activity>
<activity android:name=".Email" android:label="#string/app_name" >
</activity>
<activity android:name=".Camera" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".Data" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".GFX" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".GFXSurface" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".SoundStuff" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".Slider" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".Memory" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".OpenedClass" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".Tabs" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
<activity android:name=".SimpleBrowser" android:label="#string/app_name" android:screenOrientation="portrait" >
</activity>
</application>
</manifest>

We need to provide url with https as suffix to loadUrl

In your code :
wb.loadUrl(website);
What you passed website.check the string it is valid website.Copyt the string and paste in android phone's browser then check it is display or not

Related

Android background service get killed eventhough it has return START_STICKY in it

One of the requirements in the app that I am developing is "show something on the screen on event." Basically, I made a background service and in that, I catch the screen on intent and pass it to a BroadcastReceiver. Then, in the receiver, I open an activity and "show something". However, on Android 7-8. I think the background service get killed over a night because the next day my service is not catching anything and my receiver is not receiving. I even ask for the
<uses-permission
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
permission, and override it, but the service still gets killed. You can find my Service class, Receiver class, and manifest below.
Service class
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class Services extends Service {
private static final String TAG = "Services";
private BroadcastReceiver sReceiver;
public static final String ALARM_ALERT_ACTION = "com.android.deskclock.ALARM_ALERT";
public IBinder onBind(Intent arg) {
return null;
}
public int onStartCommand(Intent intent, int flag, int startIs) {
Log.i(TAG, "onStartCommand: " + this.toString() + " sReceiver = " + sReceiver);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(ALARM_ALERT_ACTION);
sReceiver = new Receivers(new Handler());
registerReceiver(sReceiver, filter);
if(intent != null){
LUtil.appendToLogs("Service onStartCommand " + intent.getAction() + " intent catched.");
}
return START_STICKY;
}
#Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(sReceiver);
}
}
Receiver class:
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Handler;
import android.util.Log;
import com.mytoz.app.object.CommercialData;
import java.io.File;
import java.util.ArrayList;
public class Receivers extends BroadcastReceiver {
private static final String TAG = "Receivers";
private final Handler handler;
public Receivers(Handler handler) {
this.handler = handler;
}
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive: id = " + this.toString());
Log.i(TAG, "intent.getAction() " + intent.getAction());
LUtil.appendToLogs("onReceive " + intent.getAction() + " intent passed to receiver.");
if(LUtil.isPowerOff){
LUtil.isPowerOff = false;
return;
}
if (intent.getAction() != null) {
if(intent.getAction().equals(Services.ALARM_ALERT_ACTION)){
LUtil.lastAlarmAlert = System.currentTimeMillis();
Log.i(TAG, "onReceive: LUtil.lastAlarmAlert = " + LUtil.lastAlarmAlert);
return;
}
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
final int mode = am.getMode();
if (AudioManager.MODE_IN_CALL == mode) {
Log.i(TAG, "onReceive: in call");
// device is in a telephony call
} else if (AudioManager.MODE_IN_COMMUNICATION == mode) {
Log.i(TAG, "onReceive: commuunication");
// device is in communiation mode, i.e. in a VoIP or video call
} else if (AudioManager.MODE_RINGTONE == mode) {
Log.i(TAG, "onReceive: ringtone");
// device is in ringing mode, some incoming is being signalled
} else {
// SHOW SOMETHING
}
} else {
}
}
}
}
My Manifest:
<?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="">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission
android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<application xmlns:tools="http://schemas.android.com/tools"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#mipmap/app_logo"
android:label="#string/app_name"
android:largeHeap="true"
android:roundIcon="#mipmap/app_logo"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:hardwareAccelerated"
android:name=".Mytoz">
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="false" />
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<service android:name=".Services" />
<service
android:exported="false"
android:name=".FirebaseJobService">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
</intent-filter>
</service>
<service
android:name=".PushHandleService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:enabled="true"
android:exported="true"
android:name=".BootCompletedReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:enabled="true"
android:exported="true"
android:name=".UpdateReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<activity
android:name=".SplashScreen"
android:theme="#style/SplashTheme" android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".networking.CrashReportHandle" />
<activity android:name=".LoginActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".MainActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CommercialVideo" android:taskAffinity=".CommercialVideo" android:excludeFromRecents="true" android:configChanges="orientation"
android:screenOrientation="portrait" android:launchMode="singleTop"/>
<activity android:name=".ShopActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".InterestActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity
android:name=".SignUpActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize" />
<activity android:name=".MyAdsActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SignUpThirdActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SignUpSecondActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".RegisterActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SettingsFirstActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SettingsSecondActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".SettingsThirdActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ItemDetailActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CheckoutActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".DeliveryActivity" android:configChanges="orientation"
android:screenOrientation="portrait" android:windowSoftInputMode="stateVisible|adjustResize" />
<activity
android:configChanges="orientation"
android:screenOrientation="portrait"
android:name="com.braintreepayments.api.BraintreeBrowserSwitchActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="${applicationId}.braintree" />
</intent-filter>
</activity>
<activity android:name=".PaymentActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CreditCardActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".OfferActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".ConfirmationActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".AdsSecondActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".CustomAdsVideoActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".OrderActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity android:name=".OrderDetailsActivity" android:configChanges="orientation"
android:screenOrientation="portrait" />
<activity
android:name=".SmartyAdsActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
</application>
</manifest>

((ChuckApplication) getActivity().getApplication()).setCurrentGame(c) in Fragment

I'm currently studying a trivia style app and I'm using it in a Fragment. If I use Activities instead of Fragments, the code works:
((ChuckApplication)getApplication()).setCurrentGame(c);
But once I cast it for an activity it keeps on getting an error. The code is:
((ChuckApplication)getActivity().getApplication()).setCurrentGame(c);
The whole code is for this fragment is:
public class Activity_Home_Language extends Fragment implements OnClickListener{
Intent intent;
ImageButton btnToggle;
Button btnExam,btnReview;
TextView txtTitle;
View rootView;
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.layout_home_language, container, false);
btnToggle = (ImageButton) rootView.findViewById(R.id.btnToggle);
btnExam = (Button) rootView.findViewById(R.id.btnExam);
btnReview = (Button) rootView.findViewById(R.id.btnReview);
txtTitle = (TextView) rootView.findViewById(R.id.txtTitle);
btnToggle.setOnClickListener(this);
btnExam.setOnClickListener(this);
btnReview.setOnClickListener(this);
//FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
//transaction.add(R.id.frameContent, new Activity_Home());
//transaction.add(R.id.framePager2, new ViewPagerMunicipalities());
//transaction.add(R.id.frameDestPager, new ViewPagerDes());
//transaction.commit();
//for fading animation
return rootView;
}
#Override
public void onClick(View v) {
if(v==btnToggle){
Activity_Main.mSlideHolder.open();
}
else if(v==btnExam){
FragmentTransaction transaction = getFragmentManager().beginTransaction();
//transaction.addToBackStack(null);
transaction.replace(R.id.frameContent, new Activity_Question_Exam_Home()).commit();
}
else if(v==btnReview){
//enable this to move to move to a Activity or fragment activity
//intent = new Intent(rootView.getContext(), Activity_About.class);
//startActivityForResult(intent,0);
//Get Question set //
List<Question> questions = getQuestionSetFromDb();
//Initialise Game with retrieved question set ///
GamePlay c = new GamePlay();
c.setQuestions(questions);
c.setNumRounds(getNumQuestions());
((ChuckApplication) getActivity().getApplication()).setCurrentGame(c);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frameContent, new Activity_Home_Language_Review()).commit();
//transaction.addToBackStack(null);
//transaction.commit();
//FragmentTransaction transaction = getFragmentManager().beginTransaction();
//transaction.addToBackStack(null);
//transaction.replace(R.id.frameContent, new Activity_Question_Review_Home()).commit();
}
else {
}
}
/**
* Method that retrieves a random set of questions from
* the database for the given difficulty
* #return
* #throws Error
*/
private List<Question> getQuestionSetFromDb() throws Error {
int diff = getDifficultySettings();
int numQuestions = getNumQuestions();
DBHelper myDbHelper = new DBHelper(getActivity());
try {
myDbHelper.createDataBase();
} catch (IOException ioe) {
throw new Error("Unable to create database");
}
try {
myDbHelper.openDataBase();
}catch(SQLException sqle){
throw sqle;
}
List<Question> questions = myDbHelper.getQuestionSet(diff, numQuestions);
//List<Question> questions = myDbHelper.getQuestionSet(diff, 2);
myDbHelper.close();
return questions;
}
/**
* Method to return the difficulty settings
* #return
*/
private int getDifficultySettings() {
SharedPreferences settings = getActivity().getSharedPreferences(Constants.SETTINGS, 0);
int diff = settings.getInt(Constants.DIFFICULTY, Constants.MEDIUM);
return diff;
}
/**
* Method to return the number of questions for the game
* #return
*/
private int getNumQuestions() {
SharedPreferences settings = getActivity().getSharedPreferences(Constants.SETTINGS, 0);
int numRounds = settings.getInt(Constants.NUM_ROUNDS, 20);
return numRounds;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
}
Please help. I'm stuck at that line.
Here's the application:
package com.example.civilserviceexamreviewer;
import android.app.Application;
import com.example.civilserviceexamreviewer.quiz.GamePlay;
public class ChuckApplication extends Application{
private GamePlay currentGame;
/**
* #param currentGame the currentGame to set
*/
public void setCurrentGame(GamePlay currentGame) {
this.currentGame = currentGame;
}
/**
* #return the currentGame
*/
public GamePlay getCurrentGame() {
return currentGame;
}
}
Here's the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.civilserviceexamreviewer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.civilserviceexamreviewer.Activity_Splash1"
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.example.civilserviceexamreviewer.Activity_Splash2"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activity_Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.civilserviceexamreviewer.Activity_Question_Review_Home"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.civilserviceexamreviewer.Activity_About"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.civilserviceexamreviewer.Activity_Choices"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<application
android:allowBackup="true"
android:name="com.example.civilserviceexamreviewer.ChuckApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name">
</application>
</manifest>
The way that you're accessing the Application (or its subclass) from within your Fragment is fine and correct. Since the error you're getting is a ClassCastException, I think that your problem is that you haven't declared your custom Application subclass in the AndroidManifest.xml's application tag. For this reason, calling .getApplication() will actually return an object of type android.app.Application which cannot be typecast to your custom Application class. Perhaps you did do this in your original Activity-based project, but forgot to do so when creating the Fragments-based project?
Example of how to declare your Application subclass in the manifest file:
<application
android:name="com.example.civilserviceexamreviewer.ChuckApplication"
android:icon="..."
android:label="...">
</application>
So, the complete manifest you posted in your question should actually be:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name="com.example.civilserviceexamreviewer.ChuckApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.civilserviceexamreviewer.Activity_Splash1"
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.example.civilserviceexamreviewer.Activity_Splash2"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Activity_Main"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.civilserviceexamreviewer.Activity_Question_Review_Home"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.civilserviceexamreviewer.Activity_About"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.civilserviceexamreviewer.Activity_Choices"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>

WebView is not showing html page on all version of emulator it is showing only on android 2.2?

This is the activity where html file is loaded from asset folder
public class MapActivity extends Activity {
#SuppressLint("SetJavaScriptEnabled") private WebView myWebView;
private String url ="file:///android_asset/Map.html";
#SuppressLint("SetJavaScriptEnabled")
#SuppressWarnings("deprecation") #Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String url = new String("file:///android_asset/Map.html");
setContentView(R.layout.leaflet_map);
this.setTitle("Location Map");
// Obtain the webView by ID
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
initComponent();
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
// performance hacks!
webSettings.setRenderPriority(RenderPriority.HIGH);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
// multi-touch zoom
webSettings.setBuiltInZoomControls(true);
/* webSettings.setDisplayZoomControls(false);*/
myWebView.getSettings().setLoadsImagesAutomatically(true);
myWebView.setWebViewClient(new WebViewClient());`enter code here`
myWebView.loadUrl("file:///android_asset/Map.html");
myWebView.setWebViewClient(new WebViewClient());
} public void initComponent(){
generateId(); } public void generateId(){
myWebView = (WebView) findViewById(R.id.webView); } }
My manifest file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19"/>
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#drawable/location_icon"
android:label="#string/app_name"
android:theme="#style/Background" >
<activity
android:name="com.locationTracker.periscope.MapActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.CreateIssue"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.SettingPage"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.ProjectList"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.AndroidXMLParsingActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.SingleMenuItemActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.Walk_IssueActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity
android:name="com.locationTracker.periscope.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>
</application>

UnityPlayerActivity not getting onCreate() log

I am trying to extend UnityPlayerActivity with the help of docs.unity3d. I have a simple jar file with MainActivity class and also included the file classes.jar to the libs folder. My class file has following code.
package com.example.testactivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.unity3d.player.UnityPlayerActivity;
public class MainActivity extends UnityPlayerActivity
{
#Override
public void onCreate(Bundle savedInstanceState) {
Log.i("Hiren","==============ON CREATE CALLED==============");
super.onCreate(savedInstanceState);
}
public static void callMe()
{
Log.i("Hiren","==============Function CALLED==============");
}
}
I can call the static function callMe () through my c# script but my onCreate() is not called at the start of the activity. My C# script is
private static FBShare _instance;
public static FBShare Instance
{
get
{
if(_instance == null)
_instance = new FBShare();
return _instance;
}
}
private AndroidJavaClass cls_Fb = new AndroidJavaClass("com.example.testactivity.MainActivity");
public void CallMe()
{
using(AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using(AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
cls_Fb.CallStatic("callMe");
}
}
When I call "CallMe" method, I get log of being called. but I didnt get any log from onCreate().
AndroidMenifest.xml file contains
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testactivity.MainActivity"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
<application
android:label="#string/app_name"
android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
</activity>
<activity android:name="com.unity3d.player.VideoPlayer"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation" >
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
<uses-library android:name="com.google.android.maps" />
<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_INTERNET" />
</application>
</manifest>
as nicolas said, check the manifest
make sure this section is correct
<activity
android:name=".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>

Why is my billing service not being called?

I am trying to implement the in app billing and I am using http://www.anddev.org/advanced-tutorials-f21/simple-inapp-billing-payment-t52060.html as my example. I have copied every file in the tutorial and only changed the name of the package. I changed my manifest so that it looks exactly like the one in the tutorial (mine has a few more things in there). As I was debugging I noticed that in my version the BillinService class was never called.
In the tutorial the Billing service's onCreate method is called after BillingHelper.setCompletedHandler is called
protected static void setCompletedHandler(Handler handler){
mCompletedHandler = handler;
}
However after it is called in my program it just continues.
Here is my review.class
package com.cellphone;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import com.cellphone.BillingHelper;
import com.cellphone.astralweb.R;
public class Review extends Activity implements OnClickListener {
private Context mContext;
private static final String TAG = "BillingService";
static SharedPreferences prefs;
static boolean lite;
private Button purchaseButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.reviewpage);
prefs = getSharedPreferences("Settings", 0);
lite = prefs.getBoolean("isLite", true);
String iflite = "";
if (lite) {
iflite = "-lite";
}
TextView msg1 = (TextView) findViewById(R.id.tvreview);
msg1.setText(Html
.fromHtml(cleanhtml(getText("http://www.cellphonesolutions.net/upgrade-"
+ getResources().getString(R.string.Country) + iflite))));
purchaseButton = (Button) findViewById(R.id.btntowebsite);
purchaseButton.setOnClickListener(this);
mContext = this;
startService(new Intent(mContext, BillingService.class));
BillingHelper.setCompletedHandler(mTransactionHandler);
}
public Handler mTransactionHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
Log.i(TAG, "Transaction complete");
Log.i(TAG, "Transaction status: "
+ BillingHelper.latestPurchase.purchaseState);
Log.i(TAG, "Item purchased is: "
+ BillingHelper.latestPurchase.productId);
if (BillingHelper.latestPurchase.isPurchased()) {
System.out.println("hi");
}
};
};
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btntowebsite:
if (BillingHelper.isBillingSupported()) {
BillingHelper.requestPurchase(mContext,
"android.test.purchased");
// android.test.purchased or android.test.canceled or
// android.test.refunded or com.blundell.item.passport
} else {
Log.i(TAG, "Can't purchase on this device");
purchaseButton.setEnabled(false); // XXX press button before
// service started will
// disable when it shouldnt
}
break;
default:
// nada
Log.i(TAG, "default. ID: " + v.getId());
break;
}
}
public String cleanhtml(String original) {
String finalText = original.replaceAll("<![^>]*>", "");
return finalText;
}
public String getText(String uri) {
HttpParams httpParams = new BasicHttpParams();
// 30seconds and it stops
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
HttpConnectionParams.setSoTimeout(httpParams, 30000);
DefaultHttpClient client1 = new DefaultHttpClient(httpParams);
HttpGet request = new HttpGet(uri);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
try {
String response_str = client1.execute(request, responseHandler);
return response_str;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "";
}
}
#Override
protected void onDestroy() {
BillingHelper.stopService();
super.onDestroy();
}
}
Because the BillingService is never called when I first create my review class, the BillingHelper.instantiateHelper is never called
protected static void instantiateHelper(Context context, IMarketBillingService service) {
mService = service;
mContext = context;
}
so my mService and mContext come up null when I try to press my button.
Thank you for helping me out.
EDIT here is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cellphone.astralweb" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application android:theme="#style/CustomTheme" android:icon="#drawable/icon_paid" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name="com.cellphone.Splash" 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.cellphone.LocationServiceNotification" android:screenOrientation="portrait"
android:label="#string/app_name" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="com.cellphone.LOCATIONSERVICENOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Registration" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.REGISTRATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.CreateAccount" android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.cellphone.CREATEACCOUNT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Activate" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.ACTIVATE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.ImTracking" android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.cellphone.IMTRACKING" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.SpecialAdapter" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.SPECIALADAPTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.AddPerson" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.ADDPERSON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.TrackingMe" android:label="#string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.cellphone.TRACKINGME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.InviteFollower" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.INVITEFOLLOWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Settings" android:label="#string/app_name" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.TabPage" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="com.cellphone.TABPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Review" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.REVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.help" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.HELP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.Maps" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.MAPS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.HelloItemizedOverlay" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.HELLOITEMIZEDOVERLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.History" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.HISTORY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name="com.cellphone.MyCustomLocationOverlay" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.MYCUSTOMLOCATIONOVERLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="com.cellphone.UpdateLocation" android:label="#string/app_name" android:theme="#android:style/Theme.NoTitleBar" android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.cellphone.UPDATELOCATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<service android:name=".BillingService" />
<receiver android:name=".BillingReceiver">
<intent-filter>
<action android:name="com.android.vending.billing.IN_APP_NOTIFY" />
<action android:name="com.android.vending.billing.RESPONSE_CODE" />
<action android:name="com.android.vending.billing.PURCHASE_STATE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
The problem was in my manifest, I named my service wrong
it should be
<service android:name="com.cellphone.BillingService" />
not <service android:name=".BillingService" />

Categories

Resources