I am developing a Web App with android studio.. I need to have the access open the storage in mobile phone how can I do that?
Here's my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.blogspot.httpsmekomik.appmatkomik">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
</activity>
<activity android:name=".splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private AdView mAdView;
WebView webview;
#Override
public void onBackPressed() {
if (webview.canGoBack()) {
webview.goBack();
} else {
super.onBackPressed();
}
}
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
webview = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.getSettings().setSupportZoom(true);
webview.setWebViewClient(new WebViewClient());
webview.loadUrl("https://mekomik.blogspot.my");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
If require more information from me, please let me know.
I hope you can help me, thanks.
Related
I am trying to use FCM to make push notifications but when I use the FCM test notification system, I don't recieve any notification. I don't think I need any code for that purpose except for my registration token which I obtain like this
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
I then store it in a database and copy-paste it so that there is no change. But still I am not recieving any notification. I even added the onMessageRecieved function
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
if (remoteMessage.getData().size() > 0) {
// Handle message within 10 seconds
handleNow(remoteMessage.getNotification().getBody());
}
if (remoteMessage.getNotification() != null) {
// Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
public void handleNow(String body) {
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,"Alerts")
.setSmallIcon(R.drawable.logo)
.setContentTitle("Stice Alerts")
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setSound(defaultSoundUri)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(body));
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(100,builder.build());
}
Here is my notification channel
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Alerts";
String description = "For alerts when someone is going";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel("Alerts",name,importance);
channel.setDescription(description);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
My android manifest file
<?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="com.example.jobifyme">
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".DeleteTask"/>
<activity android:name=".OurTeam" />
<activity android:name=".TaskView" />
<activity android:name=".AddAlert" />
<activity android:name=".AddTask" />
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<activity android:name=".TaskList"
android:parentActivityName="com.example.jobifyme.FirstScreen" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.jobifyme.FirstScreen" />
</activity>
<activity android:name=".FirstScreen" />
<activity android:name=".StartingPage" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#drawable/logo" />
<meta-data
android:name="com.google.firebase.messaging.Alerts"
android:value="#string/default_notification_channel_id" />
<meta-data
android:name="firebase_messaging_auto_init_enabled"
android:value="false" />
<meta-data
android:name="firebase_analytics_collection_enabled"
android:value="false" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Can anyone tell me what I might be doing wrong?
While sending out your notifications from Firebase Cloud Messaging, make sure the channel set is equal to your channel name Alerts
I am learning to develop apps for Android but I am stuck with this topic:
https://www.tutorialspoint.com/android/android_broadcast_receivers.htm
I have visited numerous sites with examples, downloaded source code and tried in two different computers with Android Studio and tried in a virtual and physical device, but I can't figure out where the problem is.
MANIFEST
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.AIRPLANE_MODE" />
<action android:name="android.intent.action.TIME_TICK" />
<action android:name="com.example.myapplication.TEST_BROADCAST" />
</intent-filter>
</receiver>
</application>
MyReceiver.java
public class MyReceiver extends BroadcastReceiver{
String logPrefix = "Android : ";
#Override
public void onReceive(Context context, Intent intent) {
Log.d(logPrefix, "Broadcast received");
Toast.makeText(context, "Intent Detected.", Toast.LENGTH_LONG).show();
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
String logPrefix = "Android : ";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(logPrefix, "The onCreate() event");
}
public void broadcastIntent(View view){
Log.d(logPrefix, "Sending broadcast...");
Intent intent = new Intent("com.example.myapplication.TEST_BROADCAST");
sendBroadcast(intent);
}
}
I followed https://developers.google.com/analytics/devguides/collection/android/v4/ to implement google analytics in my android app. But it is not showing any data.
Can anyone help?
Manifest file:
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name=".AnalyticsApplication">
<activity android:name="com.xxx.xxxx.SplashScreen"
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.xxx.xxxx.LoginScreen"
android:screenOrientation="portrait"/>
<activity android:name="com.xxx.xxxx.ForgotPasswordScreen"
android:screenOrientation="portrait"/>
<activity android:name="com.xx.xxx.SignupScreen"
android:screenOrientation="portrait"/>
<activity android:name="com.xxx.xxx.HomeScreen"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.xxx.xxxx.SplashScreen" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="#xml/global_tracker"/>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
AnalyticsApplication
public class AnalyticsApplication extends Application {
private static GoogleAnalytics sAnalytics;
private static Tracker mTracker;
#Override
public void onCreate() {
super.onCreate();
sAnalytics = GoogleAnalytics.getInstance(this);
}
synchronized public Tracker getDefaultTracker() {
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
if (mTracker == null) {
mTracker = sAnalytics.newTracker(R.xml.global_tracker);
}
return mTracker;
}
}
HomeScreen
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_screen);
Helper.printLog(tag, "onCreate");
AnalyticsApplication application = (AnalyticsApplication)
getApplication();
mTracker = application.getDefaultTracker();
mTracker.setScreenName("home screen");
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
onclick(){
mTracker.send(new HitBuilders.EventBuilder()
.setCategory("Action account")
.setAction("account clicked")
.build());
changeFragment(new AccountFragment());
}
app-gradle
dependencies{
compile 'com.google.android.gms:play-services-analytics:10.2.4'}
project-gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.0.0'
}
Try firebase analytics firebase is a google product to build high quality apps and its uses Google Analytics. Firebase and google analytics are same
Visit - https://firebase.google.com/docs/analytics/
Hope this help
I am doing a project using android studio. I have converted my website into an android application. In my android application when I change my android mobile's orientation from vertical to horizontal mode, my application gets reloaded from the first page.
The android application code is given below.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.nandha.firstproject.MainActivity">
<WebView
android:id="#+id/myWebView"
android:layout_width="368dp"
android:layout_height="495dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.nandha.firstproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView myWebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.myWebView);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.loadUrl("http://192.168.43.75/login.php");
myWebView.setWebViewClient(new WebViewClient());
}
#Override
public void onBackPressed() {
if (myWebView.canGoBack()) {
myWebView.goBack();
} else {
super.onBackPressed();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.nandha.firstproject">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I change my orientation to horizontal mode it gets reloaded as shown below from the first page
Now, I need only the page in horizontal mode for which I changed to horizontal orientation and not from the previous page.
my problem is I change the orientation to horizontal mode only for 2nd page. But, my application gets reloaded from 1st page in horizontal orientation
Kindly help me to fix this problem.
I made an app using Lynda's tutorial of Building Mobile Apps Using Google Maps API V2(http://www.lynda.com/Android-tutorials/Building-Mobile-Apps-Google-Maps-Android-API-v2/133347-2.html).
I am stuck on Chapter 2 ( Creating You First Map) . I followed each and everything but still my device shows a blank screen with Google Written in Bottom Left Corner and Zoom In and Zoom Out buttons.It looks like it is not able to load the map.
MainActivity.java
package com.example.map;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import android.os.Bundle;
import android.app.Dialog;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
private static final int GPS_ERRORDIALOG_REQUEST = 9001;
GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(servicesOK()){
Toast.makeText(this, "Ready To Map!",Toast.LENGTH_SHORT ).show();
setContentView(R.layout.avtivity_map);
}
else{
setContentView(R.layout.activity_main);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public boolean servicesOK(){
int isAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if(isAvailable == ConnectionResult.SUCCESS){
return true;
}
else if(GooglePlayServicesUtil.isUserRecoverableError(isAvailable)){
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable, this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
}
else{
Toast.makeText(this, "Can't Connect",Toast.LENGTH_SHORT ).show();
}
return false;
}
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.example.map.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.example.map.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.map.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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBdhCuM37w_myIbi87dMDwRnwd383UwXSk" />
</application>
</manifest>
Avtivity_map.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</RelativeLayout>
Please help me solve this. Why aren't maps coming on screen.
I am making a Google Science Fair project in which this app has a role to play.
Any help will be appreciated.